I have a dedicated page for every team member on my website. The title of the page is their first and last name. For every post on my site, I have two ACF ‘author’ fields. I’m trying to write a query to determine if the current team member has any posts where author_1 or author_2 contains their name.
I’m currently getting 0 posts returned even though I’m positive I should be getting some. Below is my code.
function hide_cotw_heading(){
$title = get_the_title();
global $post;
$latest_posts= get_posts( array(
'category' => 9,
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'author_1',
'value' => $title,
'compare' => 'LIKE',
),
array(
'key' => 'author_2',
'value' => $title,
'compare' => 'LIKE',
),
)
) );
if($latest_posts){
return 'Has posts';
} else{
return 'No posts';
}
}
2
Answers
I have revised your code, so please try this one
could you give this a try?