Custom Taxonomy Filter in WordPress Admin
If you have a lot of custom posts on your website, then sometimes it would be much easier to filter them by a specific taxonomy when you manage them in your WordPress admin.
Yes, search is also ok, but maybe a taxonomy filter will be just what you need? Here is how it is going to look like in WordPress admin:

Below is the code that allows to add a taxonomy filter for a specific taxonomy:
<?php
add_action( 'restrict_manage_posts', 'rudr_taxonomy_filter' );
function rudr_taxonomy_filter( $post_type ) {
// do nothing it it is not a post type we need
if( 'lesson' !== $post_type ) {
return;
}
$taxonomy_name = 'course_category';
// get all terms of a specific taxonomy
$courses = get_terms(
array(
'taxonomy' => $taxonomy_name,
'hide_empty' => false
)
);
// selected taxonomy from URL
$selected = isset( $_GET[ $taxonomy_name ] ) && $_GET[ $taxonomy_name ] ? $_GET[ $taxonomy_name ] : '';
if( $courses ) {
?>
<select name="<?php echo $taxonomy_name ?>">
<option value="">All courses</option>
<?php
foreach ( $courses as $course ) {
?><option value="<?php echo $course->slug ?>"<?php selected( $selected, $course->slug ) ?>><?php echo $course->name ?></option><?php
}
?>
</select>
<?php
}
}
What is worth to keep in mind here:
- I used
$post_type
argument of the function in order to make a condition, so the filter will be displayed only for a specific post type. But this argument is available only since WordPress 4.4, so if you’re using an older version of WP, please useglobal $typenow
instead. - If you do not know where to insert the code, please read this tutorial.
- Please take a look at line 26, the string “All courses” can also be printed dynamically, for example:
$taxonomy->labels->all_items
but of course you have to get a taxonomy object first with$taxonomy = get_taxonomy( $taxonomy_name )
.
And also it is possible to simplify the filter by changing HTML to wp_dropdown_categories()
and why not let’s extend it to multiple taxonomies.
add_action( 'restrict_manage_posts', 'rudr_taxonomy_filter' );
function rudr_taxonomy_filter( $post_type ){
// let's decide about post type first
if( 'my_post_type' !== $post_type ){
return;
}
// pass multiple taxonomies as an array of their slugs
$taxonomies = array( 'taxonomy_1', 'taxonomy_2' );
// for every taxonomy we are going to do the same
foreach( $taxonomies as $taxonomy ){
$taxonomy_object = get_taxonomy( $taxonomy );
$selected = isset( $_GET[ $taxonomy ] ) ? $_GET[ $taxonomy ] : '';
wp_dropdown_categories(
array(
'show_option_all' => $taxonomy_object->labels->all_items,
'taxonomy' => $taxonomy,
'name' => $taxonomy,
'orderby' => 'name', // slug / count / term_order etc
'value_field' => 'slug',
'selected' => $selected,
'hierarchical' => true,
)
);
}
}

Misha Rudrastyh
Hey guys and welcome to my website. For more than 10 years I've been doing my best to share with you some superb WordPress guides and tips for free.
Need some developer help? Contact me
Misha Rudrastyh, your posts are great. Simple yet effective. Thank you for the tutorials.
I’m glad you like them, you’re welcome :)
how can i get post with no category ?w
It’s really works. Thanks a lot.
How to change this for specific category names?
Hi Fabio,
If you need this just for a few specific terms or categories, I recommend you to look at
include
parameter ofget_terms()
function.Or, as an option, you can do it in static HTML.
Thank you!
Thank you so much for this post!
Always welcome :)
Did I have to specify something when I create the custom taxonomy or custom post?
Because, the custom taxonomy is add in the filter bar and it appear in the URL when I try it, but it didn’t filter… My list of post stay the same with all the results and I have no error.
Hi Phil,
Maybe you have
pre_get_posts
conflict somewhere? By the way, does the search in this post type work?Hello Misha,
That’s fantastic! but I have a question: by default they show only the “publish” custom post types, it’s possible to show some other post status? In my case I have custom post status that I need to show on the filter.
Many thanks in advance
Hello,
When you filter, what is in URL?
Hello Misha,
Finally I found a metod that make it. I replace the line:
.. with …
With this two lines appear all the list of custom taxonomy in the dropdown.
Thank you!
I’m glad you’ve figured it out 🙃
Feel free to ask if you have any other questions.
hi
thanks for your great post
how can i create filter like that in front end without plugin?
is there any example or sample code?
thanks
Hi,
Yes, absolutely, here it is.
Thanks so much for this tutorial! It really helped.