Discover in this tutorial how to display the results of FacetWP filters in a different page using code.
FacetWP is a fantastic plugin for filtering content. In fact, it’s the one I use on this site to make it easy to search for tutorials.
The operation of the plugin depends on two elements: on one hand the filters (facets) and on the other hand the templates. The latter is where the results are displayed.
By default, the results are displayed on the same page where the filters are.
In most cases this is the most appropriate behavior (as in this website). But what happens if you want to open a new page with the results?
Then you just have to modify a little the usual flow with FacetWP.
Let’s see how to do it:
Steps to display FacetWP results on a new page
1. Create filters and templates in FacetWP
This step is the same step you always take when using FacetWP.
Create one or more filters:
And create a template:
2. Install and activate the Submit addon
Once you have your filters and template configured, install and activate the Submit addon. It is free, so it will download directly from the link above.
3. Modify the search button and hide the template on the search page
On the page where you want to display the filters, add both the filters and the template, as you normally do.
Now come the two different steps:
1- On the one hand, you have to modify the search button as follows:
Where you will replace /results/ with the URL where you want to display the results.
2- On the other hand you have to hide the FacetWP template
To do this add the following to the style.css file:
Here you must replace
.page-id-148 with the ID of your search page.
With this you get:
- Let the search button send to a new results page.
- Hide the results on the search page.
4- Add the template to the results page
This step is also identical to what you would do in any other case.
In the results page you just have to add the template you have created in FacetWP.
You can do this using the shortcode directly in the block editor. For example:
Or if you want to use a specific page template in your theme you can do it using FacetWP functions.
You got it.
Do you want to display FacetWP results on a new page? Now you know how to do it.
If you have any question, please leave it in the comments. And if you want to give me a suggestion for future snippets, please send it through the contact form.
Benefits of being a subscriber. 🙂