You can save the $post
in some temp variable and just set the $post
back to the temp variable
global $post;
while ( have_posts() ) : the_post();
//Set up custom query
$args = array(
//Query args
);
$custom_query = new WP_Query( $args );
//Custom query loop:
while ( $custom_query->have_posts() ) : $custom_query->the_post();
// Save global post into temp variable
$temp_post = $post;
//Display some data,
//then set up a custom query again
$args = array(
//Different query args
);
$custom_nested_query = new WP_Query( $args );
//Nested custom query loop
while ( $custom_nested_query->have_posts() ) : $custom_nested_query->the_post();
//Do stuff, then reset to $custom_query since
//I still need the post before $custom_query proceeds with the loop and loads the next one
endwhile;
// Set the global $post back to the first custom query
$post = $temp_post;
//Display some more data from post queried by $custom_query before $nested_query was created
endwhile;
wp_reset_postdata();
endwhile;
Or just use foreach($custom_nested_query->posts as $mypost)
.