How to Add a Custom Taxonomy Filter to Your WordPress Admin List
Content
If you've created custom taxonomies with the Custom Post Type UI plugin, you might want to filter your admin list view by those terms to make content management easier. A common question from users is why some newly created taxonomies show a filter dropdown while older ones do not, or how to add this functionality in the first place.
Why This Happens
The Custom Post Type UI plugin handles the registration of your post types and taxonomies. However, the administrative interface for filtering posts by taxonomy is not automatically generated for all taxonomies by WordPress core. The appearance of these filters can depend on several factors, including the order of registration or specific settings. This is not a bug in CPTUI but a standard WordPress behavior that requires a custom code solution.
The Most Common Solution: Custom Code
The most reliable way to add a filter for your custom taxonomy is to add a small code snippet to your theme's functions.php file or a site-specific plugin. This code hooks into the WordPress admin to display a dropdown filter.
Step-by-Step Code Implementation
- Access Your Code: Use a code editor and access your theme's
functions.phpfile. We recommend using a child theme to prevent your changes from being overwritten by theme updates. - Add the Filter Code: Copy and paste the following code, making sure to replace 'your_post_type' with your actual custom post type slug and 'your_taxonomy' with your custom taxonomy slug.
add_action('restrict_manage_posts', 'filter_post_type_by_taxonomy'); function filter_post_type_by_taxonomy() { global $typenow; $post_type = 'your_post_type'; // Replace with your post type $taxonomy = 'your_taxonomy'; // Replace with your taxonomy if ($typenow == $post_type) { $selected = isset($_GET[$taxonomy]) ? $_GET[$taxonomy] : ''; $info_taxonomy = get_taxonomy($taxonomy); wp_dropdown_categories(array( 'show_option_all' => sprintf( __( 'Show all %s', 'textdomain' ), $info_taxonomy->label ), 'taxonomy' => $taxonomy, 'name' => $taxonomy, 'orderby' => 'name', 'selected' => $selected, 'show_count' => true, 'hide_empty' => true, )); }; } add_filter('parse_query', 'convert_id_to_term_in_query'); function convert_id_to_term_in_query($query) { global $pagenow; $post_type = 'your_post_type'; // Replace with your post type $taxonomy = 'your_taxonomy'; // Replace with your taxonomy $q_vars = &$query->query_vars; if ( $pagenow == 'edit.php' && isset($q_vars['post_type']) && $q_vars['post_type'] == $post_type && isset($q_vars[$taxonomy]) && is_numeric($q_vars[$taxonomy]) && $q_vars[$taxonomy] != 0 ) { $term = get_term_by('id', $q_vars[$taxonomy], $taxonomy); $q_vars[$taxonomy] = $term->slug; } } - Save and Test: Save the file and navigate to your custom post type's list in the WordPress admin. You should now see a dropdown filter for your custom taxonomy.
Important Considerations and Troubleshooting
- Plugin Conflicts: If the code does not work, try disabling other plugins to rule out a conflict. Another plugin might be interfering with the admin query.
- Theme Functions: Ensure your theme does not already have conflicting code for admin filters. The code must be added correctly to the
functions.phpfile. - Page Builders and Advanced Filters: For more complex filtering needs on the public-facing front end of your site (e.g., for visitors to filter portfolio items), this admin code will not work. The Custom Post Type UI team has often pointed users to third-party solutions like FacetWP for front-end filtering systems.
- Support Scope: Remember, the Custom Post Type UI plugin registers the taxonomies, but how they are used and displayed in the admin or on the front end is handled by WordPress core, your theme, or other plugins.
By following this guide, you can significantly improve the content management experience for yourself and your clients by making it easy to find and filter content based on custom classifications.
Related Support Threads Support
-
Show Custom Taxonomy in Custom Admin Menuhttps://wordpress.org/support/topic/show-custom-taxonomy-in-custom-admin-menu/
-
Taxonomy filter in admin post listhttps://wordpress.org/support/topic/taxonomy-filter-in-admin-post-list/
-
Displaying More Than 5 Posts Per Taxonomyhttps://wordpress.org/support/topic/displaying-more-than-5-posts-per-taxonomy/
-
Custom post and it’s Taxonomies don’t show up on dashboard menushttps://wordpress.org/support/topic/custom-post-and-its-taxonomies-dont-show-up-on-dashboard-menus/
-
Use custom taxonomy for filtering / conditionhttps://wordpress.org/support/topic/use-custom-taxonomy-for-filtering-condition/
-
Getting custom taxonomies into my RSShttps://wordpress.org/support/topic/getting-custom-taxonomies-into-my-rss/
-
How to use Taxnomoy as Related Post?/Pages?https://wordpress.org/support/topic/how-to-use-taxnomoy-as-related-post-pages/
-
Custom taxonomy: on the taxonomy term page show other taxonomy termshttps://wordpress.org/support/topic/custom-taxonomy-on-the-taxonomy-term-page-show-other-taxonomy-terms/
-
Custom taxonomy displaying all possible content instead of specific to posthttps://wordpress.org/support/topic/custom-taxonomy-displaying-all-possible-content-instead-of-specific-to-post/
-
Is there a way to display a custom taxonomy as a filter in All Postshttps://wordpress.org/support/topic/is-there-a-way-to-display-a-custom-taxonomy-as-a-filter-in-all-posts/
-
NAV Menu options unclearhttps://wordpress.org/support/topic/nav-menu-options-unclear/
-
taxonomy vs custom fieldhttps://wordpress.org/support/topic/taxonomy-vs-custom-field/
-
Display taxonomy description in admin metabox?https://wordpress.org/support/topic/display-taxonomy-description-in-admin-metabox/
-
Adding taxonomies to multiple posts displayed on one pagehttps://wordpress.org/support/topic/adding-taxonomies-to-multiple-posts-displayed-on-one-page/
-
Show filter for custom taxonomy in admin columnhttps://wordpress.org/support/topic/show-filter-for-custom-taxonomy-in-admin-column-2/
-
How to create a filter for my custom Taxonomieshttps://wordpress.org/support/topic/how-to-create-a-filter-for-my-custom-taxonomies/
-
How to menu_position taxonomies?https://wordpress.org/support/topic/how-to-menu_position-taxonomies/
-
filtering post with custom categories?https://wordpress.org/support/topic/filtering-post-with-custom-categories/
-
Need Custom Taxonomy to show in ACF location rules dropdown optionshttps://wordpress.org/support/topic/need-custom-taxonomy-to-show-in-acf-location-rules-dropdown-options/
-
Custom post type taxonomieshttps://wordpress.org/support/topic/custom-post-type-taxonomies-3/
-
Custom Taxonomy for Recipes Bloghttps://wordpress.org/support/topic/custom-taxonomy-for-recipes-blog/
-
Filtering custom taxonomies in WP Bakery Page Builderhttps://wordpress.org/support/topic/filtering-custom-taxonomies-in-wp-bakery-page-builder/
-
Search Custom Taxonomies in Media Libraryhttps://wordpress.org/support/topic/search-custom-taxonomies-in-media-library/
-
Taxonomy below the excerpthttps://wordpress.org/support/topic/taxonomy-below-the-excerpt/
-
Display taxonomy in post and excerpthttps://wordpress.org/support/topic/display-taxonomy-in-post-and-excerpt/