Simple Posts Filter by Custom Taxonomy in WP Admin Without Plugins
Okay, what if you have a lot of posts (or maybe custom post type posts) on your blog? How do you manage them in your admin panel? You use search for that, don’t you?
Let me show you a very simple code example, which will add on your posts page a filter by taxonomy terms (like category filter).

And that is the code for your functions.php
file:
function rudr_posts_taxonomy_filter() {
global $typenow; // this variable stores the current custom post type
if( $typenow == 'post' ){ // choose one or more post types to apply taxonomy filter for them if( in_array( $typenow array('post','games') )
$taxonomy_names = array('platform', 'device');
foreach ($taxonomy_names as $single_taxonomy) {
$current_taxonomy = isset( $_GET[$single_taxonomy] ) ? $_GET[$single_taxonomy] : '';
$taxonomy_object = get_taxonomy( $single_taxonomy );
$taxonomy_name = strtolower( $taxonomy_object->labels->name );
$taxonomy_terms = get_terms( $single_taxonomy );
if(count($taxonomy_terms) > 0) {
echo "<select name='$single_taxonomy' id='$single_taxonomy' class='postform'>";
echo "<option value=''>All $taxonomy_name</option>";
foreach ($taxonomy_terms as $single_term) {
echo '<option value='. $single_term->slug, $current_taxonomy == $single_term->slug ? ' selected="selected"' : '','>' . $single_term->name .' (' . $single_term->count .')</option>';
}
echo "</select>";
}
}
}
}
add_action( 'restrict_manage_posts', 'rudr_posts_taxonomy_filter' );

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.