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',
You’re right. I saw that in another post as you were replying. Thanks!