If you have loads of content on your website, adding WordPress category filters can significantly help your website visitors find the resource they are looking for. In this blog post, I’ll lay down a step-by-step guide to help you set up category filters so your website visitors can filter post by category in WordPress easily.
Navigation plays a big part in the website’s UX. If your website visitors are not able to easily locate the page they are looking for, you probably need to improve your website’s navigation. One way to do this is by adding category filters or to filter post by category in WordPress.
This article will help you create category filters for your website content with the Posts Table Pro plugin. By the end of this tutorial, you’ll be able to display your website content in structured tables with category-based filters like so:
What are WordPress categories and why use them as filters?
WordPress categories are default taxonomies that come with every WordPress website. You can use categories to organize your content more effectively. For example, if you have a tech review blog, you can structure your articles in categories such as camera, PC, mobile, and so on.
If you have ever created a post on WordPress, you must have noticed that the ‘Uncategorised’ category is selected by default. You can change this to any other category. Or if you want, you can add new categories (more on this in the next section).
Since WordPress categories are used to bundle similar content on a website, it makes sense to use them as filters. This will allow your website visitors to filter post by category in WordPress of a particular sub-topic by selecting the said category.
Categories are not used just to organize the content of website posts. You can use them to organize any WordPress post type, such as Products (WooCommerce plugin), Events (Events Manager plugin), or Templates (Page builder plugins such as Elementor). Basically, if there is any batch of content that can be structured more efficiently, you can do it with WordPress categories. And if the same content can be organized categorically, it can be used as a filter to help users refine their search.
Now that we know the purpose of WordPress categories and why they are perfect for filters, let’s see how you can add new categories.
How to add new WordPress categories?
Since categories are hierarchical WordPress taxonomies, you can create them to add more sections or sub-sections for your website’s content. If you do not have a category for your new post, you can easily add it. Here’s how you can do it:
Towards the right, you can see the categories with relevant details such as description, slug, and the number of posts in that category.
You can repeat the steps above to add more categories to your post type. And once you have your categories in place, you can return to your post and assign them to new categories you created.
If you want to create an entirely new post type for your content, check out this detailed guide: Creating custom post types in WordPress.
How to filter post by category in WordPress
Now let’s see how you can display the categories as filters for your website content. By default, there’s no direct way to do this. You can always take the code route but that will require you to work with the functions.php file and add functions such as add_function, get_terms, add_action, add_filter, and $args to create a category filter. If you are not a developer, here’s another and much simpler method.
To display categories as filters on your WordPress website, we will use the Posts Table Pro plugin. The posts table pro plugin lets to display any post on your website in the easiest way possible.
The plugin also allows you to add impressive navigation options. You get multiple options such as dropdown taxonomy filters, search bar, page navigation, etc. And you can make all the necessary changes even if you are not familiar with HTML, CSS, PHP or any other web development languages.
Since we’ll be using the Posts Table Pro plugin to display categories as filters, you need to download it. If you do not have the plugin, you can get it here:
If you haven’t installed the plugin on your website, you can follow these steps:
The Posts Table Pro plugin is now active on your website. Now we can set up category filters for any post type.
Setting up the Posts Table Pro plugin
Before adding ajax category filters to your post type, you have to make a few adjustments to the Posts Table Pro plugin. For this, go to the WordPress admin dashboard → Settings → Posts Table Pro.
Here you’ll see a list of options. You can use these options to customize your posts table and add elements such as filters, search bar, navigation, etc. Let’s check out the options you need to adjust here:
- Post type: This option allows you to select the post type you want to display and add category filters.
- Columns: Since your post-type content will be displayed in a table, you can choose the data you want to display. For example, you can show the title, author, featured image, publish date, category, and excerpt.
- Content and excerpt length: If you want to display the content and excerpt in the table, you can limit the length of characters by entering a word limit text field.
- Loading: If you have many posts on your website, you can set up lazy load, post limit in a single search, and posts per page to improve page load time.
- Sorting: Posts Table Pro lets your visitors sort the table contents by clicking on the table heads. You can set up a default sort order by selecting the respective options from the list.
Controls:
This option will let you use your post categories as filters. Here’s what you need to do:
- Search filters: Select the search filter as Custom from the dropdown list.
- Custom filters: Enter ‘Categories’ as the search filter. If you wish to add more search filters like tags or custom taxonomies, you can enter the tags separated by a comma.
- Search box: This option allows you to select the location of your search box. For this tutorial, I’m going with ‘Above table’. You can also add a search reset link to clear the search filters by enabling the reset link checkbox.
- Page length: This lets you change the position of the ‘Show [x] per page’ dropdown list.
- Post totals and pagination: This option lets you select the position of pagination options.
- Design: All the options here will let you customize the frontend design of the table. You can customize the borders color, background color, body text color, and spacing.
- Advanced: Here, you can select the pagination type from the list and enable shortcodes and caching for faster page load time.
By adding ‘categories’ as the search filter, your visitors can filter the posts by selecting the category from the dropdown list.
Displaying posts with category filters
Now that you have everything ready, we can use a shortcode to display post tables with category filters.
For this, you simply need to add the [posts_table]
shortcode on any page and update it. If you want to create a new page for your content with category filters, this is how you can do it.
This is what the posts table looks like after making all the changes mentioned above:
Here the users can filter the post-type content by using the dropdown filters or by simply clicking on the category in the Categories column.
You can always go back to the Posts Table Pro settings page to adjust the table layout and contents further. Just click the Save Changes button to make the changes live.
Start filtering posts by categories on your website
With the steps mentioned above, you can easily add category filters to any custom post type content on your website and let your visitors filter post by category in WordPress. However, if you want to create a new category or a custom taxonomy, you can do so with the free Easy Post Types & Fields plugin. The plugin will help you create a new custom post type, custom fields, or taxonomy in the easiest way possible. The plugin is available for free on wordpress.org.
If you want to create a custom taxonomy filter on your website, you can check out this detailed guide. It covers all the necessary steps, from creating a custom taxonomy to displaying the taxonomy as filters for your website visitors.
With the Posts Table Pro plugin, you can use your categories as filters. You can also display any content on your website in a tabular format. With the Posts Table Pro plugin, you can:
- Display custom post type content in searchable tables.
- Manage large quantities of content with AJAX lazy loading and filters.
- Display a table on any page on your website.
- Embed audio or video to create an audio or video playlist.
- Add quick search, sort, and filter options to help visitors refine their search.
- Take full control of how your content is displayed on the front end.
What do you think about the Posts Table Pro WordPress plugin? If you are looking for an easy way to display any post-type content with AJAX filters, Posts Table Pro is perfect for you!
This content was originally published here.