Support

Account

Forum Replies Created

  • Envirodefence,

    It looks like you need to do a meta_query in your get_posts() function. You can find the docs here: https://www.advancedcustomfields.com/resources/query-posts-custom-fields/. Look under the Custom Fields advanced section for an example on how to query a checkbox. Essentially, you will add a query field like so:

    'meta_query'	=> array(
    			'key'	  	=> 'featured_type',
    			'value'	  	=> 'about',
    			'compare' 	=> '=',
    		),
    	),
    
  • Jez,

    If I am understanding you correctly, you have a Custom Field in CPT b and you want CPT a to have access to the options that are selected?

    To target a specific field in a CPT you would change this block

    $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);
    		}
    

    to something like

    
    $cpt_custom_field = get_field($cpt_id, 'the_name_of_the_specific_field');
    foreach ($cpt_custom_field['choices'] as $value=>$label) {
        $field['choices'][ $value ] = [ $label ];
    }
    

    Or whatever you want to replace the information with. Nested repeater fields are slightly more complicated, but code examples for that are in the docs. You could create a colors array and assign the select to those, you can grab all post names from a CPT and assign those, etc. You just need to change the above code to match what you are loading into the choices field.

  • Yes, I am actually doing this with a dropdown, but it is the same concept. The Documentation can be found here: https://www.advancedcustomfields.com/resources/acf-load_field/.

    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');
Viewing 3 posts - 1 through 3 (of 3 total)