How to Let Users Filter Posts and Pages 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.

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.

Having said that, let’s take a look at how to easily let users filter posts and pages in WordPress.

Allowing Users to Easily Filter Posts and Pages

First thing you need to do is install and activate the Search & 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 & 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 & Filter plugin documentation

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.

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

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

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

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

Filter posts by category and tags

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:

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

Here is how it would look:

Adding all fields to the filter

Now instead of using 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"]

Allowing users to select multiple items in the filter using checkbox

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:

Advance filtering with headings and different field types

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

You can also use these shortcodes inside a text widget. If the shortcode doesn’t work in your text widget, then please see our guide on how to use shortcodes in your WordPress sidebar widgets.

We hope this article helped you learn how to let users filter posts and pages in WordPress. You may also want to see these actionable tips to drive traffic to your WordPress site.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

The post How to Let Users Filter Posts and Pages in WordPress appeared first on WPBeginner.

Source: http://www.wpbeginner.com/plugins/how-to-let-users-filter-posts-and-pages-in-wordpress/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s