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 FileBird: Filtering attachments by folder

FileBird: Filtering attachments by folder

FileBird is one of many WordPress plugins that provide more control over the attachments in the Media Library. You can use the FileBird folders in Relevanssi searches to filter attachments based on their folder. Here’s a simple function you can add to your site: Once you add this, you can use the folder parameter to…

Read more FileBird: Filtering attachments by folder 0 Comment on FileBird: Filtering attachments by folder
Continue reading WPML: Replacing posts with translations

WPML: Replacing posts with translations

Here’s a different approach to WPML searching. By default, you have two options. You can include posts in all languages in the results, or you can only use the current language. This solution checks for matches also in other languages. If Relevanssi finds any, this script then replaces them with the translated posts. You get…

Read more WPML: Replacing posts with translations 0 Comment on WPML: Replacing posts with translations
Continue reading Searching for all descendants of a page

Searching for all descendants of a page

If you want to restrict a search to a page and all it’s children, you can add a post_parent parameter to the search, and that’s it – but that only includes the direct children of the page. What if you want to include page, it’s children, all the grandchildren and their children? In that case,…

Read more Searching for all descendants of a page 2 Comments on Searching for all descendants of a page
Continue reading WooCommerce: Return only exact matches for SKU searches

WooCommerce: Return only exact matches for SKU searches

This little filter function works on relevanssi_hits_filter. When a search query is made that matches an SKU (or any other custom field, but SKUs are the most likely scenario here), only results that match the SKU will be returned. For this to work, Relevanssi must be set to index the _sku custom field (because otherwise,…

Read more WooCommerce: Return only exact matches for SKU searches 1 Comment on WooCommerce: Return only exact matches for SKU searches
Continue reading Wishlist Member: Sorting the posts by membership levels

Wishlist Member: Sorting the posts by membership levels

Someone wanted a way to prioritize posts that are targeting particular Wishlist Member membership level. The basic implementation here is simple: create a relevanssi_hits_filter function that will sort the posts by the level. There’s a trick to this, though, as Wishlist Member does not provide a way to check the level of one post. There’s…

Read more Wishlist Member: Sorting the posts by membership levels 0 Comment on Wishlist Member: Sorting the posts by membership levels
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 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 custom field, but it’s easy…

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 33 Comments on Category filter for search results pages