How to filter custom post types by taxonomy in WordPress

how to create a custom WordPress taxonomy filter

WordPress custom post types are perfect for smartly organizing website content. Allowing visitors to filter any content by taxonomies can help visitors to navigate more quickly. In this tutorial, I’ll explain how you can add custom WordPress taxonomy filters to your custom post types easily.

Since WordPress taxonomies are used to group content based on shared properties, it makes perfect sense to use them as filters.

If you already have custom post types and taxonomies set up on your website, it’ll only take minutes to set up and use taxonomies as filters. Just follow this quick guide and by the end of this tutorial, you’ll be able to add taxonomy filters to custom post types and display them in searchable tables with the Posts Table Pro plugin like so:

custom filters taxonomy preview

What are Custom Post Types?

By default, every WordPress website divides content into two post typesPosts & Pages. These two post types come preinstalled and if you wish to add more, you can do it by adding custom post types.

If you have a post category that you want to group separately, adding a custom post type is highly recommended. For example, if you publish customer success stories on your website along with blog posts, having customer success stories set up separately will help you organize them more efficiently.

If you do not have custom post types set up on your WordPress website, you can check out this detailed guide on creating custom WordPress post types. It covers everything from setting up Easy Post Types and Fields plugin to creating and displaying custom post types and taxonomies.

What are taxonomies in WordPress?

Simply put, taxonomies are methods to group posts or content together based on a unique relationship between them. WordPress has Categories and Tags taxonomies for default post types and you can use them in combination to group content based on their nature.

As Tickera said, "Mastering WordPress taxonomies is crucial for creating a well-organized and user-friendly website." That's because they provide unlimited ways of structuring and filtering your website content.

For example, if you have a blog section on your website, you can tag blog posts based on their nature such as updates, announcements, tutorials, news, or any custom category.

categories tags and WordPress taxonomy filter
Categories, tags, and a custom taxonomy (Genre)

Taxonomies can be hierarchical too. This means every ‘topic’ can have its own ‘sub-topics’ to further organize content on the website. For example, a product review site can divide tech product reviews into these categories: mobile phones, laptops, cameras, TVs, etc.

What is a taxonomy filter?

Custom taxonomy filters bring the power of taxonomies to the front end of your website by allowing your website visitors to filter by them. The terms for a particular custom taxonomy are listed in a filter dropdown so that users can select which ones they wish to view.

For example, the following screenshot includes 2 types of custom taxonomy filters:

  1. Two taxonomy filter dropdowns above the list of documents: Year and Format.
  2. These taxonomies also appear as table columns, so that users can click to filter the list by that term.
custom filtered content by taxonomy

As you can see, using taxonomies as filters makes it easier for users to pull content from a particular niche. They can select the taxonomy term they're interested in and instantly see the results.

Taxonomy filters are an alternative to taxonomy archive pages. That's because instead of only listing items with a particular term, you can display all items and allow users to filter by a specific term. This adds flexibility to your site.

How to display and filter custom post types by taxonomy

Now let’s see how you can use custom taxonomies as filters for your custom post type content.

To display and filter custom post type content, we’ll use the Posts Table Pro plugin. The plugin is designed to display and customize any post type content in the easiest way possible.

The plugin comes with extensive options to tweak and customize post tables and make them look the way you want.

Let’s see how you can use Posts Table Pro to filter custom post types by taxonomy.

Before you begin…

As I mentioned earlier, make sure you have custom post types and custom taxonomies set up on your website.

If not, you can follow this guide to create WordPress custom post types. If you already have custom post types set up on your website and want to add custom taxonomies, consider checking out this custom WordPress taxonomies guide.

For this tutorial, I’ve created a ’Movie Reviews’ custom post type and added the ‘Movie Genre’ taxonomy to filter movie reviews. Here’s what the custom post type content looks like:

Movie reviews custom post type data

Now that you have your custom post type, taxonomies, and CPT content in place, let’s start setting up filters.

Filter custom post types by taxonomy using Posts Table Pro

To filter custom post types, you need to install the Posts Table Pro plugin. Here’s how:

  1. Download the Posts Table Pro plugin. If you do have the plugin, you can get it here.
  2. Log in to the WordPress admin dashboard and go to Plugins → Add New.
  3. Click on the Upload button and upload the Posts Table Pro zip file.
  4. Click on the Install button and activate the plugin.
  5. Follow the setup wizard instructions to create your first table.

Now you are ready to set up a custom WordPress taxonomy filter for your custom post type posts.

For this, go to the Posts Table Pro settings page. You can access it by going to the WordPress admin dashboard → Post Tables → Settings.

As soon as you install the plugin, a setup wizard will launch automatically. This wizard will provide you with a step-by-step guide to help you create your first table.

In addition, you can create new tables whenever you want by navigating to Post Tables → Add New. 

Here are some steps to help you through the process:

  1. Start by giving a name to your table and selecting the post type you want to display. If you don't have a content type, you can create one using the Easy Post Types and Fields plugin, which is free.
  2. Choose the movies or pages you want to add to the table. The options on this page will depend on which post type you selected on the previous page. For example, if you select an entry with a custom taxonomy then those taxonomies will be listed here.
  3. Customize the table to your liking. For instance, to display the movie title, summary, release year, and genre, select the type of column from the dropdown and click 'Add'. It then appears in the list of columns above. You can also reorder the columns by dragging and dropping the sort icon or column heading.
  4. You can make it easier for users to find what they want by adding filters to your table. For instance, if you have sorted your movie reviews by genre, you can add a filter for that. The filters appear as dropdowns above the table and you can add as many as you like. Note that the options on this page will change depending on which post type you selected on the first page.
  5. You can then set the default sorting option and the sort direction.
  6. To filter your custom post types by taxonomy, you need to create the table twice - once in the numbered list and again underneath in the text. Create a table in the numbered list and then create another table underneath the numbered list in the text. Ensure that both tables contain the same information.
  7. Finally, the last page confirms that you have finished creating the table and provides instructions on how to insert it onto your site. You can copy and paste the shortcode provided and add it to any page or post where you want the table to appear.

Inserting the table

After creating a table, the next step is to choose where to display it on your website. Here are two ways to insert the table into your WordPress site:

  1. If you're using the Gutenberg block editor, you can simply select and add the table using the 'Post Table' block.
  2. Alternatively, you can copy the shortcode from the last page of the table builder or from the main Tables page in the Post Tables section of the WordPress admin. Then, paste it anywhere on your site where you want the searchable database to appear, no matter what the topic is.

That’s it!

Your custom post type table with a WordPress taxonomy filter is now published on the website. This is how our table with the Genre filter.

Custom taxonomy filter for custom post type preview

You can also display the custom taxonomies as table columns. This will allow your viewers to sort the table by clicking on the table column and filter the table by clicking on the taxonomy term. This will work even if you do not have custom filters enabled.

How to create a custom taxonomy programatically

For the developers among you, you might want to create a custom taxonomy using PHP code rather than using a plugin. Whichever method you use to create it, you can create custom taxonomy filters using the Posts Table Pro plugin.

Only experienced developers should use the code solution, otherwise use the Easy Post Types and Fields plugin recommended above.

Use the register_taxonomy function to create a new WordPress custom taxonomy. You should use the taxonomy's unique identifier slug as the first argument, and an array of post types to attach the taxonomy to as the second. Finally, you need an array with the remaining arguments.

As a minimum, you will end up with a custom taxonomy code snippet similar to this for a non-hierarchical taxonomy like tags. Use the WordPress developer documentation on registering a custom taxonomy to customize it as needed:

add_action('init', function() {
register_taxonomy('book_author', ['book'], [
'label' => __('Authors', 'txtdomain'),
'hierarchical' => false,
'rewrite' => ['slug' => 'book-author'],
'show_admin_column' => true,
'show_in_rest' => true,
'labels' => [
'singular_name' => __('Author', 'txtdomain'),
'all_items' => __('All Authors', 'txtdomain'),
'edit_item' => __('Edit Author', 'txtdomain'),
'view_item' => __('View Author', 'txtdomain'),
'update_item' => __('Update Author', 'txtdomain'),
'add_new_item' => __('Add New Author', 'txtdomain'),
'new_item_name' => __('New Author Name', 'txtdomain'),
'search_items' => __('Search Authors', 'txtdomain'),
'popular_items' => __('Popular Authors', 'txtdomain'),
'separate_items_with_commas' => __('Separate authors with comma', 'txtdomain'),
'choose_from_most_used' => __('Choose from most used authors', 'txtdomain'),
'not_found' => __('No Authors found', 'txtdomain'),

How to filter by custom field in WordPress

A lot of people contact us asking how to allow visitors to their WordPress website to filter by custom field. Unfortunately this isn't possible because that's not what custom fields are for.

Custom fields are designed for storing and displaying unique data about a WordPress post or page. For example, you might use a custom field to store a reference number.

Of course, if data is unique to that page or post then it doesn't make sense to filter by it. After all, filtering is all about grouping items that share common features, such as all posts from a certain year.

That's why you should use custom taxonomies instead of WordPress custom fields to store data that you wish to filter by. Custom taxonomies are all about grouping items and lend themselves perfectly to filtering.

Start displaying taxonomies as filters with Posts Table Pro

Custom taxonomies are a powerful tool for organizing your website content. Allowing your visitors to filter by taxonomy supercharges them even more, putting instant answers at their fingertips.

Katie KeithCEO, Barn2 Plugins

With the steps mentioned above, you can easily create, set up, and display taxonomies as filters on your website with Posts Table Pro. This makes navigation easier for your website visitors.

With the Posts Table Pro plugin, you can:

  • Effortlessly display custom post type content in sortable tables.
  • Add category, tags, and custom taxonomy filters.
  • Display any content on your WordPress website in tabular format.
  • Embed video and audio directly into the table.

You also get a no questions asked 30-days money-back guarantee with the Posts Table Pro plugin so you can test it on your website without any worry.

If you are looking for an easy way to display custom post type content with a custom WordPress taxonomy filter, Posts Table Pro is perfect for you!


    • Hi, Stathis. Thanks for your comment and interest in Posts Table Pro! Yes, you can use our plugin to achieve this on your site. I see that you also sent us a message asking the same via our chat widget, which I have since responded to in detail. Please could you check your inbox for my response and let me know if you have any more questions.

Please share your thoughts...

Your email address will not be published. Required fields are marked *