Create a Query

Search & Filter relies heavily on the creation of Queries. Using our Query Builder you can easily create queries and fine tune them to display content on your site.

Combine Search & Filter Queries with Search & Filter Fields to allow your visitors filter down exactly what they’re looking for, keeping them on your site for longer and increasing conversions!

Note: For this guide, you’ll need to ensure that Search & Filter version 3 is installed and up to date.

Navigate to the Query Builder

  1. Log into your WordPress admin dashboard.
  2. Hover over the Search & Filter menu on the left-side of the screen and click on the Queries option.
  3. Click on the Add new button at the top of the page.

Configure the Query Settings

  1. Next, you’ll need to add a name for your query. This name won’t be visible on the front end of your site, however, it will be used by the Search & Filter plugin to differentiate this query from other queries.
  2. Check that the Enabled switch is on. This switch is on by default when you first create a query, but keep in mind that if this switch is off, the Query won’t be available to use.
  3. In the Location tab, you can determine and change the expected Location of the query as well as the expected source of the WordPress query.

    In short, our plugin can identify and modify a WordPress query to showcase different results on a page based on a user’s interaction.

    For this example, we’ll leave everything as it is and use the default options (including keeping the Autodetect query loop option turned on).

    If you’d like to find out more information about what these settings do, and how you can utilize them, you can click here.

    Also, you can find more on how to create a query that relies on a Shortcode here.
  4. Next, click on the Query tab.

    There are a lot of different options here, so let’s try to break them down:
    • Use Indexer (Pro): this setting will enable Search & Filter’s Indexer. You can find out more about the Indexer here, but in short, this feature facilitates faster and dynamic search and filtering. For this example, we’ll keep the feature off and rely on WordPress’ query.
    • Post types: in this field, you’ll need to specify the expected post types of the query. You can choose to add multiple post types, like Media and Pages, as well as custom post types.

      Note: Some Location types are locked into the post type of the archive itself (e.g. WooCommerce Shop only allows for Products).

      Depending on the post types added to this field, you’ll get different results when searching and/or filtering a query.

      For this guide, we’ll use the default Posts option.
    • Post status: similar to Post types, this field allows you to choose multiple possible post statuses to search from.

      We’ll keep the default option of Published for the time being.
    • Posts per page: this field allows you to change the number of returned posts per page for each query. The maximum number is 100. We’ll be using the default 10 for now.
    • Sort order: this option allows you to fine-tune the query further so that the appearance order of posts after a search or filter interaction has occurred is specified. There’s a long list of options you can choose to order based on, but for now, we’ll keep this option turned off. Here’s a screenshot of the options, though, for reference:
    • Sticky posts: you can choose to Ignore sticky posts from the query. There are some extra options for this field like Excluding them, Showing them, or Only take into consideration sticky posts.

      For now, we’ll use the default option, which is Ignore.
    • Field relationship: this setting allows you to adjust the behavior of included fields for a query. In short, for posts that utilize added fields (e.g. WooCommerce products that have product category and product tag), this setting will determine the relationship the fields have between them.

      We’ll use the default option for now, but if your posts utilize multiple post fields, you can read our document here for more information on how you can use this.
    • Exclude Current Post: this switch is set to Yes by default, and will exclude the post that the Query is added to.
  5. When you’re done with the Query tab, you can then click on the Save button to save the query. Regarding the tabs that we didn’t utilize in this example:
    • The Taxonomies and Post Meta fields allow you to further fine-tune the query so that specific taxonomies and post meta are taken into account when the Query is utilized. You can learn more about how to configure these fields here.

      If not used, the Query will rely on WordPress query’s default options for these fields.
    • The Live Search tab is a feature that was upgraded in version 3 of Search & Filter. It allows your users to complete searches without triggering a page refresh. This feature is great if you’re looking to create a dynamic search for your site, but we won’t use it for this example. Click here to find out more about this feature.

Well done! You’ve just created your first query! This is how it will look like after you have clicked on the Save button:

The highlighted number is the Query’s ID. This ID is required for some custom configuration and code snippets, but for the time being, you can ignore it.

Connected Fields

If you scroll down below the query builder, you’ll notice the Connected Fields section:

This is one of the places where you can create Fields to search and filter the Query you created.

Continue to the next guide about creating fields.