group search results by post type?

You can run the same loop multiple times by using rewind_posts() to output each type separately.

if( have_posts() ){
    $types = array('post', 'lesson', 'series');
    foreach( $types as $type ){
        echo 'your container opens here for ' . $type;
        while( have_posts() ){
            the_post();
            if( $type == get_post_type() ){
                get_template_part('content', $type);
            }
        }
        rewind_posts();
        echo 'your container closes here for ' . $type;
    }
}

Leave a Comment