How to group search results by post type and only if post type result is not empty?
The only way is to count them or (re)request them via WP_Query. I think I prefer the first solution because it’s the less complex. <?php if (have_posts()) : ?> <?php // We change the definition of the array to be able to store the count of each post_type $types = array(‘post’ => 0, ‘videos’ => … Read more