i've done a fair look round before posting this and i'm not getting much luck. Here's the scenario. I have a search query which retrieves normal posts and two additional custom post types (distributors wanted and events), and displays the results separated into their own divs using a foreach loop, thusly: if( have_posts() ){ $types = array('post', 'tribe_events', 'distribute'); $counter = 1; foreach( $types as $type ){ echo '<div class="results '; echo $type. '">'; if($type == 'post'){ echo '<h4><i class="fa fa-newspaper-o"></i> Articles</h4>'; } if($type == 'distribute'){ echo '<h4><i class="fa fa-truck"></i> Distributors Wanted</h4>'; } if($type == 'tribe_events'){ echo '<h4 class="events">Events</h4>'; } echo '<ul class="looplist">'; while( have_posts() ){ the_post(); if( $type == get_post_type() ){ get_template_part('parts/search', $type); } $counter++ ; } rewind_posts(); echo '</ul></div>'; } This is all working ok, retrieving the selected parts, but there's two issues i'm not sure how to address. 1: because it's sorting results by the post date ascending (default) it's not really working well for the events (which are being handled by ['the events calendar' by Modern Tribe][1])- since they're published at arbitrary dates as listings come in, but have a specific meta value for their start dates, which i would like to order them by if possible. i've used the query for this in a normal WP_query like so: 'meta_key'=>'_EventStartDate', 'orderby'=>'_EventStartDate', 'order'=>'ASC', 2: since the code is using a foreach loop, i'm not sure how to approach hiding empty results, which means even if no results are returned for the post type in question it still renders the heading and container div. Can anyone suggest a solution? i did onder about conditionally passing $args to each post type, but i tried a few things and all i got was a headache and a white screen.. apologies if my lack of knowledge is a hindrance here i am a relative newbie! Cheers! Pete [1]: https://theeventscalendar.com/