On my search page I want to group the posts by post type. To do this I've got the following:
add_filter('posts_groupby', 'group_by_post_type' );
function group_by_post_type( $groupby ) {
global $wpdb;
if( is_search() ) {
return $wpdb->posts.'.post_type';
}
}
Before adding the filter I had 9 results, however after adding the filter I only have 3 results, one of each post type.
What am I doing wrong?