So i have some pages where i want to show my custom post type 'events' only by the last 5 posts (secondary query: WP_Query object) and some pages where i want to show all posts (for instance archive template as is_main_query). I hate duplicate code - but i cant seem to outthink a way to not write loop code, even though it should display same structure, in separate places.
For instance; in my loop.php file I loop through all main query posts with have_posts(). But in my secondary queries where I use WP_Query, I cant call that loop file because its not a main query. Then I'll have to look up that specific query with $secondary_query->have_posts(), so i end up writing loop code where i call WP_Query..
So to wrap it up :-) is there a way I dont know about to use my loop file on secondary queries??
This is kind of what I want to do:
$event_query = new WP_query($args); get_template_part('loop', 'home'); //calling loop.php wp_reset_postdata();