I’ve never tried this but I can see how it might be problematic.
What does your query look like inside the repeater?
Sure thing. It’s pretty long so here is a link to the Gist I created:
https://gist.github.com/onetrev/c44850751ec0a00678761263999888e8
Let me know if there is anything else you need. Would be super handy to figure out a way to get this to work.
Sorry to bump this, just wondering if you had any further thoughts on whether this was possible? It’s in a theme repeater if that makes any difference. Thanks!
Hi,
I was able to get a nested query working.
Here is my test repeater template.
<article>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<?php the_content(); ?>
<ul>
<?php
$args = array(
'post_type' => 'page',
'posts_per_page' => 3,
);
$test_query = new WP_Query( $args );
while ($test_query->have_posts()): $test_query->the_post();
global $post;
?>
<li class="no-img"><a href="<?php the_permalink(); ?>"><?php echo $post->ID; ?> - <?php the_title(); ?></a></li>
<?php endwhile; wp_reset_postdata(); ?>
</ul>
</article>
I believe your issue is that you need to pass a $post value to your custom field functions in order to return the correct data.
Notice the global $post;
in my template, and then the wp_reset_postdata()
.
https://gist.github.com/dcooney/357246e89c9e1b8ed4dc3bf395c07406
Can I ask why you just don’t create this query using the shortcode builder?
Excellent! That worked perfectly, I should have known I needed to access the $post data.
Not sure I understand your question regarding the shortcode builder. I have a shortcode created to load the overall repeater template but this query above is not an ajax repeater just a simple query. I don’t want an ajax load more inside another ajax load more…. if that makes sense?
Regardless, thanks a ton for the help. Cheers!
Not sure I understand your question regarding the shortcode builder.
Me neither, I think I misunderstand what was happening in your repeater template.
Glad it’s all sorted out for you.
Cheers,