I am trying to run a reverse query on a post relation field that is within a subfield repeater. My code doesn’t return any errors but the Array always comes back empty. Any idea what I’m doing wrong? Thanks!
<?php while ( have_posts() ) : the_post(); ?>
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
<?php $issues = get_posts(array(
'post_type' => 'product', // WooCommerce Custom Post Type
'meta_query' => array(
array(
'key' => 'section_contents', //this is the post relationship field, which is in a repeater subfield of 'toc_section'
'value' => '"' . get_the_ID() . '"',
'compare' => 'LIKE'
)
)
));
print_r($issues) //testing if there's anything at all in the array. Has been returning empty.
?>
<?php if( $issues ): foreach( $issues as $issues ): ?>
<?php echo get_the_title( $issues->ID ); ?>
<?php endforeach; endif; ?>
<?php endwhile; // end of the loop. ?>
would it work if you change the 2 lines to this:
<?php if( $issues ): foreach( $issues as $issue ): ?>
<?php echo get_the_title( $issue->ID ); ?>
That still returns empty. I don’t think there’s an “issue” variable anywhere.
you cant use foreach as with the same variable 😉
but your real problem is probably here:
'key' => 'section_contents', //this is the post relationship field, which is in a repeater subfield of 'toc_section'
subfield of repeater
if you have luck change this too and it works:
key' => 'toc_section_%_section_contents',
Actually, the solution is right over here: http://support.advancedcustomfields.com/forums/topic/reverse-query-relationship-subfield-which-is-nested-in-a-repeater-field/
I should have googled better before posting. 🙂
You’re right. I saw that in another post as you were replying. Thanks!
The topic ‘Reverse Query Returning Empty’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.