Home Forums ACF PRO get_posts by ACF Select field with labels


get_posts by ACF Select field with labels

  • I’m trying to query posts by a few select field’s labels. However, my query doesn’t seem to working. Am I approaching this correctly?

    function hide_cotw_heading(){
    	$title = get_the_title();
    	$args = array(
    		'cat' => 9,
    		'meta_query'    => array(
    			'relation'      => 'OR',
    				'meta_key'       => 'author_1',
    				'meta_value'     => $title
    				'meta_key'       => 'author_2',
    				'meta_value'     => $title
    	  $latest_posts = get_posts( $args );
    		return 'Has posts';
    	  } else{
    		return 'No posts';
  • First, you cannot query by the label, ACF only stores the selected value.

    Second, what type of select field are you using? Can multiple choices be selected?
    Look at this document for the difference between fields that can have single or multiple selections

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.