Continue reading Using multiple custom taxonomies

Using multiple custom taxonomies

Usually, WordPress supports one category, one tag and one taxonomy in the search, if you use the query variables to set the taxonomies. You can enter multiple taxonomies as parameters to the query, but only the first one is used. If you want to have multiple taxonomies involved, you need to build a tax_query. The…

Read more Using multiple custom taxonomies 60 Comments on Using multiple custom taxonomies
Continue reading Using Relevanssi without a search term

Using Relevanssi without a search term

…a search term present. This was originally implemented for a restaurant search, where the users can search for restaurants based on search terms, opening hours and price category. The client wished to be able to use the opening hours and price category with and without a search term. The problem……is, Relevanssi doesn’t trigger without a search term. To fix that, you need to use a new filter hook relevanssi_search_ok. Add this code to your site: add_filter( ‘relevanssi_search_ok’, ‘search_trigger’ ); function search_trigger( $search_ok ) { global $wp_query; if ( ! empty( $wp_query->query_vars[ ‘price‘ ] ) ) { $search_ok = true;……} return $search_ok; } This function will trigger Relevanssi, when the query var price appears in the query. Of course, without a search term, Relevanssi will find nothing. So, you need another function attached to relevanssi_hits_filter. It needs to have something like this: add_filter( ‘relevanssi_hits_filter’, ‘rlv_hits_filter’ ); function rlv_hits_filter( $hits…

Read more Using Relevanssi without a search term 42 Comments on Using Relevanssi without a search term
Continue reading Taxonomy archive search

Taxonomy archive search

This is a Premium feature and only applies when you index taxonomy terms. This does not apply in free Relevanssi. To include taxonomy pages (categories, tags, custom taxonomies) in the search, enable the option on the options page. There’s also the option to choose which taxonomies are included. By default empty terms (not linked to…

Read more Taxonomy archive search 49 Comments on Taxonomy archive search
Continue reading Custom weighing with relevanssi_match and relevanssi_results

Custom weighing with relevanssi_match and relevanssi_results

The relevanssi_match hook lets you modify the matches found for queries. It passes a match object, which has the post id ($match->doc), number of hits found in different parts of the post and the weight assigned to the post ($match->weight). Here’s how Relevanssi calculates the weight: Where $idf is the inverse document frequency, aka the…

Read more Custom weighing with relevanssi_match and relevanssi_results 64 Comments on Custom weighing with relevanssi_match and relevanssi_results
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, or 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…

Read more Search results breakdown by type 51 Comments on Search results breakdown by type
Continue reading Multisite searches

Multisite searches

…other hand, you can adjust the settings for each blog. Enabling the multisite search There are several ways to enable multisite searching. If you want all searches to be multisite searches, you can enable multisite searching from the Relevanssi searching settings. If you want only some searches to be multisite…searches, you need to adjust search forms to include a specific parameter that will enable the multisite searching. See “Changes to the search form” below. Changes to search results templates The search results templates require some changes, otherwise, the permalinks will be wrong. Inside the while (have_posts()) loop, add as……in the same WordPress network, use the searchblogs argument. You can add a hidden input field in the search form, for example. List the desired blog ids as the value. For example, searchblogs=1,2,3 would search blogs 1, 2, and 3. Here’s an example search form: <form action=”https://www.relevanssi.com/” method=”get”> <input id=”s” name=”s”…

Read more Multisite searches 144 Comments on Multisite searches
Continue reading Direct access to the query engine

Direct access to the query engine

Relevanssi can’t be used in any situation, because it checks the presence of search with the is_search() function. This causes some unfortunate limitations and reduces the general usability of the plugin. You can, however, access the query engine directly. There’s a function called relevanssi_do_query(), which can be used to do search queries just about anywhere. Here’s a…

Read more Direct access to the query engine 61 Comments on Direct access to the query engine