GET FREE VERSION GET THE PRO VERSION

Create Search Results Filters Based On Current Search Query

Learn how to create search results filtering rules based on current users' search query.

In this article

Overview

In this article, we will cover how to create search result filters based on the user's current search query.

Example: A user enters the search query Hoodies on Sale. We want to create a filter that shows only On Sale products if the user's search query contains the word sale.

Here are the search results before applying this filter:

Image - Search results for the query 'Hoodies on Sale'

Image - Search results for the query 'Hoodies on Sale'

And after applying it:

Image - Search results for the query 'Hoodies on Sale' with a special filter applied

Image - Search results for the query 'Hoodies on Sale' with a special filter applied

With this type of filter, you can create very complex search rules based on the current search text:

  • Show only featured products if the search text includes words like Features, Popular, or Best.
  • Show products with the color attribute set to Black if the search query includes the word Black.
  • Show products with Free Shipping if the search query contains the words free shipping.

...and so on. The number of examples is limited only by your imagination. This is a powerful filtering rule.

Below, we will cover how to create such filtering rules for all search result types: products, taxonomies, and users.

Note: Filters based on the current search query are available starting from Advanced Woo Search PRO 3.14.

Filters for Product Search Results

Let's start by creating a filter based on the current search query for product search results.

Example: Create a rule to show only On Sale products if the current query contains the word Sale.

Here are the steps to create such a filter:

1. Go to the plugin settings page -> Search Results tab, and scroll down to the Filter Results section.

2. Click the Filter products search results button and create the following filters:

Current search text -> contains -> sale AND
Product is on sale -> equal to -> Yes
OR
Current search text -> not contains -> sale AND
Product -> equal to -> Any

Filtering rules for the word 'Sale' inside a search query

Filtering rules for the word 'Sale' inside a search query

3. Now, save all changes and check your search results. The new filter should be applied to all your product search results if the user's query contains the word sale.

Show only "On Sale" products if the search query contains the word 'Sale'

Show only "On Sale" products if the search query contains the word 'Sale'

Filters for Taxonomies Search Results

Next, let's create filters for taxonomy archive page results.

Example: If the current search query contains the word colors, show all available values for the Color attribute.

To create this filter, follow these steps:

1. Go to the plugin settings page -> Search Results tab, and scroll down to the Filter Results section.

2. Click the Filter taxonomies archive pages results button and create the following filters:

Current search text -> contains -> colors AND
Term page taxonomy -> Product Color -> equal to -> Any
OR
Current search text -> not contains -> colors AND

Filtering rules for the word 'Colors' inside a search query

Filtering rules for the word 'Colors' inside a search query

3. On the same Search Results page, make sure that the search for attributes is enabled. To do this, find the Archive pages option, enable the Attributes field, and click on the gear icon next to it to enable attributes related to product colors.

Enable search for attributes taxonomies

Enable search for attributes taxonomies

4. Finally, save all changes and check the search results. If the search query contains the word color, the taxonomy results will show only values related to the Color attribute.

Show only Color attribute values if the search query contains the word 'Color'

Show only Color attribute values if the search query contains the word 'Color'

Filters for Users Pages Search Results

Finally, let's create a filter for user archive page search results.

Example: If the user's search query contains the word vendor, show only users with the role Shop Vendor.

To create this filter, follow these steps:

1. Go to the plugin settings page -> Search Results tab, and scroll down to the Filter Results section.

2. Click the Filter users archive pages search results button and create the following filters:

Current search text -> contains -> vendor AND
User role-> equal to -> Shop Vendor
OR
Current search text -> not contains -> vendor AND

Filtering rules for the word 'Vendor' inside a search query

Filtering rules for the word 'Vendor' inside a search query

3. Also, ensure that the search for users is enabled for your search form. To do this, on the same page, check the Archive pages option, and ensure that the Users field is enabled. Click the gear icon next to it and enable all user roles that you want to be included in the search.

Enable search for users archive pages

Enable search for users archive pages

4. Finally, save all the changes and check your search form. If the search query contains the word vendor, the search results will show only users with the role Shop Vendor.

Show only 'Shop Vendor' users if search text contains word 'vendor'

Show only 'Shop Vendor' users if search text contains word 'vendor'