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',
array(
'meta_key' => 'author_1',
'meta_value' => $title
),
array(
'meta_key' => 'author_2',
'meta_value' => $title
)
)
);
$latest_posts = get_posts( $args );
if($latest_posts){
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 https://www.advancedcustomfields.com/resources/query-posts-custom-fields/