I'm trying to use a custom WP_Query loop within another one to display data from the inner loop independently from the main loop. I found this solution but don't really understand how to use it. Here is the code, it works but the main loop generate duplicate posts.
<?php
// define the main query
$main_args = array(
'post_type' => 'page',
'post_parent' => '10',
);
// execute the main query
$the_main_loop = new WP_Query($main_args);
// go main query
if($the_main_loop->have_posts()) : while($the_main_loop->have_posts()) : $the_main_loop->the_post();
?>
<p>This is the content from the main loop</p>
<?php
// define the inner query
$inner_args = array(
'post_type' => 'page',
'post_parent' => '20',
);
// execute the inner query
$the_inner_loop = new WP_Query($inner_args);
// go inner query
if($the_inner_loop->have_posts()) : while($the_inner_loop->have_posts()) : $the_inner_loop->the_post();
?>
<p>This is the content from the inner loop</p>
<?php
// end the inner loop, no reset
endwhile; endif;
?>
<p>This is another content from the main loop</p>
<?php
// end the main loop
endwhile; endif; wp_reset_postdata();
?>
Thanks!