How can Users Filter Posts and Pages in WordPress
By default, on your WordPress website, you can allow users click on a category or a tag and it will bring all the posts related to that one category or that one tag. Is it posible to filter multiple posts and pages on your WordPress site? Can we add filters to WordPress site allowing users to filter posts by category, tags, post types? To get something like that going on your website let’s walk you through how to let users filter posts and pages in WordPress.
Allow Users to Easily Filter Posts and Pages
The first thing you need to do is install and activate the Search and Filter plugin. For more details, see our step by step guide on how to install a WordPress plugin.
Upon activation, the plugin will add a new menu item labeled Search and Filter to your WordPress admin bar. Clicking on it will take you to the plugin’s usage page with detailed documentation on how to use the plugin.
Search and Filter plugin comes with a shortcode which accepts different parameters to display the filtering options. You can use this shortcode in a post, page, or inside a text widget.
You can also use the shortcode as a template tag in your WordPress theme files like this:
This will display the filtering options with search, category, and tags fields.
By default, the plugin accepts search, taxonomy, post_type, and post_date as fields.
Let’s take a look at another example. This time we will include category, tags, post types, and date fields.
You will need to use the shortcode like this:
Here is how it would look:
Now instead of using the drop down select field, you can also use checkboxes and add labels for each field. To do that, you will need to add two more parameters to the shortcode.
If you use a separate page to display your blog posts, then you can add this shortcode to the page.
[searchandfilter headings="Select categories:" types="checkbox" fields="category"]
If you are using multiple fields, types, and headings, then you need to make sure that items are in the same order for each parameter.
Let’s see another example. This time we are adding category, tags, and post type fields with different headings and form field types.
[searchandfilter headings="Post type, Category, Tag" types="checkbox, select, select" fields="post_types,category,post_tag"]
This is how it would appear on your site:
You can refer to plugin’s documentation page for more ways to use the shortcode.
Latest posts by sarah ali (see all)
- How to Get Started with A/B Testing for WordPress - June 23, 2017
- Top 5 CDN Providers for WordPress: 2017 - June 22, 2017
- How to Create an Admin User in WordPress Database via MySQL. - June 20, 2017