Hi,
I have a problem related to selecting all the posts based on a sub-field value.
So, I am trying to retrieve all the publications (custom post type) that have a repeater field (bib_authors) and a sub-field (bib_author). The type of the sub-field (bib_author) it’s Post Object.
Basically I copy/pasted the code from the documentation and I replace the fields, but with no luck. I don’t receive any post …
The code:
// filter
function my_posts_where($where) {
$where = str_replace("meta_key = 'bib_authors_%", "meta_key LIKE 'bib_authors_%", $where);
return $where;
}
add_filter('posts_where', 'my_posts_where');
// args
$args = array(
'numberposts' => -1,
'post_type' => 'publications',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'bib_authors_%_bib_author',
'compare' => 'LIKE',
'value' => 'John Smith'
),
)
);
// query
$the_query = new WP_Query( $args );
?>
<?php if( $the_query->have_posts() ): ?>
<ul>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<li>
<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endwhile; ?>
</ul>
<?php else: ?>
<p>No publications.</p>
<?php endif; ?>
<?php wp_reset_query(); // Restore global post data stomped by the_post(). ?>
Here you can find the acf json export: http://seomat.com/bib/json/acf-export-2017-02-13.json
I found the problem, it expects an ID and not a NAME.
Topic closed.