Continue reading Showing only one recurring event

Showing only one recurring event

Some event calendar plugins do recurring events by creating many posts. That’s fine, until those cloned posts fill up your search results. This function, added to your theme functions.php, will only show one of each post with the same title, and will take the one with the first date. The date is checked from _EventStartDate…

Read more Showing only one recurring event 2 Comments on Showing only one recurring event
Continue reading Category filter for search results pages

Category filter for search results pages

Sometimes it’s nice to have a category filter on the search results pages: a simple dropdown where you can choose the category you want to show. It’s easy to create one using wp_dropdown_categories(), but on a search results page that’s slightly problematic, as it’ll include all categories, not just those included in the search results.…

Read more Category filter for search results pages 16 Comments on Category filter for search results pages
Continue reading Put sticky posts first in results

Put sticky posts first in results

If you want to have sticky posts first in results when they match the search query, just add this code to your theme functions.php: add_filter( ‘relevanssi_hits_filter’, ‘rlv_sticky_first’ ); function rlv_sticky_first( $hits ) { $sticky = array(); $nonsticky = array(); $sticky_post_ids = get_option( ‘sticky_posts’ ); foreach( $hits[0] as $hit ) { if ( in_array( $hit->ID, $sticky_post_ids…

Read more Put sticky posts first in results 0 Comment on Put sticky posts first in results
Continue reading Search results in random order

Search results in random order

Do you want to order your search results in random order? Here’s how: add_filter(’relevanssi_hits_filter’, ‘shuffle_search’); function shuffle_search($hits) { shuffle($hits[0]); return $hits; }add_filter(‘relevanssi_hits_filter’, ‘shuffle_search’); function shuffle_search($hits) { shuffle($hits[0]); return $hits; } Put this code in your functions.php and the search results will appear in random order. However, this only works if all the search results are…

Read more Search results in random order 1 Comment on Search results in random order
Continue reading Using Relevanssi without a search term

Using Relevanssi without a search term

Version 1.7.3 introduces the possibility to use Relevanssi without a search term. This is useful when you have extra query arguments that can be used to narrow the search, but which would be useful without a search term present. This was originally implented for a restaurant search, where the users can search for restaurants based…

Read more Using Relevanssi without a search term 42 Comments on Using Relevanssi without a search term
Continue reading Separating posts by post type

Separating posts by post type

Using the relevanssi_hits_filter, it’s easy to separate the search results by post type. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 add_filter(’relevanssi_hits_filter’, ‘separate_result_types’); function separate_result_types($hits) { $types = array(); $types[’mycustomtypethatgoesfirst’] = array(); $types[’thesecondmostimportanttype’] = array(); $types[’post’] = array(); $types[’page’] = array();   //…

Read more Separating posts by post type 28 Comments on Separating posts by post type
Continue reading Search results breakdown by type

Search results breakdown by type

Do you want to have a breakdown of search results by post type? This could be used for example to show a list of post types like books, movies, albums on a review site, and make them links to limit the search results to that post type. This is fairly easy to do with the…

Read more Search results breakdown by type 26 Comments on Search results breakdown by type
Continue reading Using the relevanssi_hits_filter hook

Using the relevanssi_hits_filter hook

One of the most useful filter hooks in Relevanssi is the relevanssi_hits_filter, which lets you modify the array of posts Relevanssi finds. The filter passes an array, where index 0 gives the list of hits in the form of an array of post objects and index 1 has the search query as a string, in…

Read more Using the relevanssi_hits_filter hook 10 Comments on Using the relevanssi_hits_filter hook