Continue reading Year filter from the search query

Year filter from the search query

A good question was asked in the post Natural-language date queries: Is it possible to extend this so that I can simply add a the year in the search and only results from that year would show? The answer is yes! Add these functions to your site: The code consists of two functions. The first…

Read more Year filter from the search query 0 Comment on Year filter from the search query
Continue reading Only return exact title matches if possible

Only return exact title matches if possible

We have posts with titles like “A perfect match”. If a user searches for this exact title, only this post should show up in the results. Otherwise, the search should run as default. There are several approaches to this, but the best is relevanssi_hits_filter. This function goes through all the posts, checks if the post…

Read more Only return exact title matches if possible 0 Comment on Only return exact title matches if possible
Continue reading Search form: Search only in titles

Search form: Search only in titles

If you want to add an option to search only in titles to your search form, here’s how. First, you need to modify the search form to add the selection. To add a simple dropdown, add this to your search form: This select element will create a small dropdown with the option to search everything…

Read more Search form: Search only in titles 0 Comment on Search form: Search only in titles
Continue reading Integrating Koko Analytics stats

Integrating Koko Analytics stats

It’s possible to integrate all kinds of external data to Relevanssi weights. Koko Analytics is a great analytics plugin. It collects stats about your visitors and stores them in the local database, which means those stats are available for Relevanssi. For some sites, this makes a lot of sense. For example, I have Kirjavinkit, a…

Read more Integrating Koko Analytics stats 0 Comment on Integrating Koko Analytics stats
Continue reading How to block searches without a search term

How to block searches without a search term

By default, Relevanssi returns all posts when searching without a search term. That’s the default WordPress behaviour. Sometimes it may not be the wanted behaviour. One reason is performance: returning all results can be very slow. To stop Relevanssi from running when there’s no search term, add this to your site: This little function will…

Read more How to block searches without a search term 2 Comments on How to block searches without a search term
Continue reading Adding a search form in the navigation menu

Adding a search form in the navigation menu

WordPress doesn’t make adding a search form in the navigation menu easy. It’s a popular request, though, and having access to the search in the site header is typical. Relevanssi itself doesn’t have opinions on the user interface. Some themes, like Twenty Twenty, include a built-in search feature in the header. That’s a good reference…

Read more Adding a search form in the navigation menu 0 Comment on Adding a search form in the navigation menu
Continue reading Modifying the search form on the fly

Modifying the search form on the fly

I set up a short coded search box to search my Learndash e-course for one specific category only: [ searchform ld_topic_category=”156″ ] It works perfectly except one thing: if no results show, it takes you to the default WordPress page and presents you with the standard search box that no longer searches category 156. This…

Read more Modifying the search form on the fly 0 Comment on Modifying the search form on the fly
Continue reading Forced phrase search with fallback

Forced phrase search with fallback

Relevanssi by default does not consider the search query a phrase, or value posts where the words in the search query appear together. Sometimes people do expect that, especially in AND searches. Relevanssi however does not have the information about the nearby words, so it’s not possible for Relevanssi to factor that in. Relevanssi does…

Read more Forced phrase search with fallback 0 Comment on Forced phrase search with fallback
Continue reading Multi-part excerpts

Multi-part excerpts

Relevanssi Premium 2.11 introduces a new feature: multi-part excerpts. There’s a new setting on the Excerpts & Highlights settings tab, “Number of excerpt snippets”, and that lets you define the maximum number of excerpt snippets Relevanssi generates for each post. How does it work This option is only available when the excerpt length is defined…

Read more Multi-part excerpts 0 Comment on Multi-part excerpts