I'm using a wp_query to find custom posts that have a specified numeric value inside of a custom field. That custom field's value is an array of numbers (IDs of selected posts using Advanced Custom Field's Relationship field).
So I am trying to find all posts that have the specified value inside of that field's array.
Here's my code:
foreach ($selectedAuthors as $myAuthor){
$args = array(
'posts_per_page' => -1,
'post_type' => 'resource',
'resource_types' => 'ml-special-reports',
'meta_query' => array (
'key' => 'qd_resource_author_selector',
'value' => $myAuthor,
),
'orderby' => 'title',
'order' => 'ASC'
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
echo '<h3>'.get_the_title($myAuthor).'</h3>';
while ( $query->have_posts() ) :
$query->the_post();
echo '<h3>'.get_the_title().'</h3>';
endwhile;
wp_reset_postdata();
}
}
If I var_dump() $selectedAuthors I get:
array(3) { [0]=> int(214) [1]=> int(216) [2]=> int(211) }
Each run through the while($query->have_posts()) returns every post of the type resource with the resource_types taxonomy term ml-special-reports regardless of whether or not $myAuthor exists in the qd_resource_author_selector custom field's array.
Any thoughts on what I'm doing wrong?