Home Forums General Issues Pre-populate radio button with CPTs? Reply To: Pre-populate radio button with CPTs?

  • Yes, I am actually doing this with a dropdown, but it is the same concept. The Documentation can be found here:

    You can use something like add_filter('acf/load_field/name=cpt_all', 'acf_load_post_types'); to limit the use to any custom fields named cpt_all. Here is the code that I am using:

    function acf_load_post_types( $field ) {
        // reset choices
        $field['choices'] = array();
    		$args = array(
    				'public' => true
    		$post_types = get_post_types($args);
    		foreach ($post_types as $post_type) {
    			if ($post_type !== 'attachment' && $post_type !== 'page')
    				$field['choices'][$post_type] = ucfirst($post_type);
        // return the field
        return $field;
    add_filter('acf/load_field/name=cpt_all', 'acf_load_post_types');