Skip Navigation

[Resolved] Nesting repeating groups programatically

This support ticket is created 2 years, 12 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 2 replies, has 1 voice.

Last updated by CraigS3893 2 years, 12 months ago.

Author
Posts
#2264841

I have a requirement to create repeating full-width blocks, with a customisable background colour and intro text. Within these blocks, I need another repeating group of info panels, containing a hyperlinked image overlaid with text. I'm creating this programatically, not using Views, and I can get the main blocks to repeat correctly, but the nested loop within them isn't outputting anything. I suspect there's a problem with the toolset_get_related_posts syntax on the inner loop.

My code is as follows:

<!-- OUTER LOOP -->
<?php
$child_posts = toolset_get_related_posts( get_the_ID(), 'campaign-block', array( 'query_by_role' => 'parent', 'return' => 'post_object' ) );
foreach ($child_posts as $child_post)
{ ?>

[BLOCK TITLE AND TEXT OUTPUT HERE, ALL WORKS FINE, AND REPEATS CORRECTLY]

<!-- INNER LOOP -->
<?php
$child_posts_blocks = toolset_get_related_posts( get_the_ID(), 'block-info-panels', array( 'query_by_role' => 'parent', 'return' => 'post_object' ) );
foreach ($child_posts_blocks as $child_post_block)
{ ?>

[NOTHING BEING OUTPUT IN THIS LOOP!]
"$child_post_block->ID" )); ?>">
"$child_post_block->ID" )); ?>" />
"$child_post_block->ID" )); ?>
"$child_post_block->ID" )); ?>

<?php }?>
<?php wp_reset_query(); ?>
<!-- /INNER LOOP -->

<?php }?>
<?php wp_reset_query(); ?>
<!-- /OUTER LOOP -->

Would appreciate any pointers. Pretty sure it's just the syntax on that inner loop that needs fixed.

#2264883

Resolved it myself. Inner loop was querying the wrong ID. Changed it to this:

$child_posts_blocks = toolset_get_related_posts( $child_post->ID, 'block-info-panels', array( 'query_by_role' => 'parent', 'return' => 'post_object' ) );

And it's now working. 🙂

#2264885

My issue is resolved now. Thank you!