filterpostpages
How to Let Users Filter Posts and Pages in WordPress
September 14th, 2018 in Wordpress |

Do you want to allow users to filter posts and pages on your WordPress site? Recently, one of our users asked us how to add filters to their WordPress site allowing users to filter posts by category, tags, post types, etc. In this article, we will show you how to let users filter posts and pages in WordPress.

Why Let Users Filter Posts and Pages in WordPress?

By default, WordPress comes with categories and tags as a way for you to sort content into topics and for your users to easily find it.

However, users can only view one category, tag, or archive page at a time and it will only show one post type.

What if you wanted users to be able to filter content in more than one category or tag? How about allowing users to view posts, pages, and custom post types at the same time?

This kind of filtering can be particularly helpful when you have a lot of content, and you want users to filter it according to their own preferences.

Allowing Users to Easily Filter Posts and Pages

The first thing you need to do is install and activate the Search & Filter plugin.

Upon activation, the plugin will add a new menu item labeled Search & 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.

searchfiltersettings

Search & 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.

1
[searchandfilter fields="search,category,post_tag"]

You can also use the shortcode as a template tag in your WordPress theme files like this:

1
<?php echo do_shortcode('[searchandfilter fields="search,category,post_tag"]'); ?>

This will display the filtering options with search, category, and tags fields.

post-filter

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:

1
[searchandfilter fields="search,category,post_tag,post_types,post_date"]

Here is how it would look:

allfieldsfilter

Now instead of using the drop down the 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.

1
[searchandfilter headings="Select categories:" types="checkbox" fields="category"]

selectfilter

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.

1
[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:

advancefiltering

Please refer to plugin’s documentation page for more ways to use the shortcode.

We hope this article helped you learn how to let users filter posts and pages in WordPress.