Skip to main content

Custom Taxonomy Filter in WordPress Admin

I’ve just created a custom post type and custom taxonomy in WordPress.

The custom post type is “product” and the taxonomy is  “metal_types“.

It’s all working well, but I want to be able to filter results based on the taxonomy in my WordPress admin page. As you have probably realised, WordPress does not natively add that functionality in, you need to do it.

Luckily, it’s very quick and simple. All you need to do is replace the ‘post_type’ and ‘taxonomy’ with yours.

Add this to Functions.php

add_action('restrict_manage_posts', 'product_type_filter');
function product_type_filter() {
 global $typenow;
 $post_type = 'product'; // change to your post type
 $taxonomy = 'metal_types'; // change to your taxonomy
 if ($typenow == $post_type) {
 $selected = isset($_GET[$taxonomy]) ? $_GET[$taxonomy] : '';
 $info_taxonomy = get_taxonomy($taxonomy);
 wp_dropdown_categories(array(
 'show_option_all' => __("Show All {$info_taxonomy->label}"),
 'taxonomy' => $taxonomy,
 'name' => $taxonomy,
 'orderby' => 'name',
 'selected' => $selected,
 'value_field' => 'slug',
 'show_count' => true,
 'hide_empty' => true,
 ));
 };
}

One thought to “Custom Taxonomy Filter in WordPress Admin”

Leave a Reply