##Grouping wordpress search result by post types
Created
April 15, 2016 15:33
-
-
Save ariona/c6d655a21ffd28f9826b4fbbd9273e35 to your computer and use it in GitHub Desktop.
Grouping wordpress search result by post types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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