I have a main query, in which I set up a new custom query to retrieve posts (think about 'related posts' or something like that). Than in each of those posts, I'm setting an other custom query, load data from a single post, then I should find a way to reset postdata to the first custom query. How can I do that? I tried wp_reset_postdata(), but that resets to main query.
A simplified code would look thus:
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();
//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;
//Display some more data from post queried by $custom_query before $nested_query was created
endwhile;
endwhile;