Group results by post type (and display the post type)
-
Hi !
I followed this bit of code I found on the knowledge base to sort my search results :add_filter('relevanssi_hits_filter', 'sort_by_post_type_relevanssi'); function sort_by_post_type_relevanssi($hits) { $types = array(); $types['tribe_events'] = array(); $types['post'] = array(); $types['page'] = array(); // Split the post types in array $types if (!empty($hits)) { foreach ($hits[0] as $hit) { array_push($types[$hit->post_type], $hit); } } // Merge back to $hits in the desired order $hits[0] = array_merge($types['tribe_events'], $types['post'], $types['page']); return $hits; }
It’s working great so far but I have two problems :
- I don’t necesserally like the fact that I need to write the post type directly in the code. In relevanssi settings, we can choose which posts type we want. How can we access those ?
- How could I display the name of the post type before the post types ? like below :
EVENTS My awesome event A great cooperation Another event NEWS A great cooperation A super news ! Pages Who are we? Contact us
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Group results by post type (and display the post type)’ is closed to new replies.