Skip to content

Instantly share code, notes, and snippets.

@ariona
Created April 15, 2016 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ariona/c6d655a21ffd28f9826b4fbbd9273e35 to your computer and use it in GitHub Desktop.
Save ariona/c6d655a21ffd28f9826b4fbbd9273e35 to your computer and use it in GitHub Desktop.
Grouping wordpress search result by post types

##Grouping wordpress search result by post types

<?php
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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment