cloning a WP_Query

You shouldn’t have to “get your query back”. Your queries are all stored in different objects– $team, $reports_played, the original $wp_query, etc. Just access the particular object that you need to use.

This is untested but to get functions like the_title working, run $query_object_name->the_post() at the top of each Loop iteration and $post = $parent_object_name->post after each sub-Loop and before returning to the parent Loop to put the global post object back to the parent object’s $post. I think that will work. wp_reset_postdata will reset to the main query so I doubt it will work for deeply nested queries.

Leave a Comment