Add a dropdown filter for each category-style taxonomy on custom post type list screens, like WordPress has for Posts.
add_action( 'restrict_manage_posts', function ( string $post_type ): void {
foreach ( get_object_taxonomies( $post_type, 'objects' ) as $taxonomy ) {
// Posts already have a category filter; skip tag-style taxonomies.
if ( 'category' === $taxonomy->name || ! $taxonomy->hierarchical || ! $taxonomy->query_var || ! $taxonomy->show_ui ) {
continue;
}
wp_dropdown_categories( [
'taxonomy' => $taxonomy->name,
'name' => $taxonomy->query_var,
'value_field' => 'slug',
'show_option_none' => $taxonomy->labels->all_items,
'option_none_value' => '',
'selected' => sanitize_title( wp_unslash( $_GET[ $taxonomy->query_var ] ?? '' ) ),
'hierarchical' => true,
'hide_empty' => false,
'show_count' => true,
] );
}
} );
Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.
WordPress gives Posts a category dropdown, but custom post types like portfolios, events or documents get nothing. This snippet adds a filter for each of their category-style taxonomies automatically.
On restrict_manage_posts, the snippet looks at every taxonomy attached to the current post type. For hierarchical, visible taxonomies with a query variable, it prints a dropdown of terms using their slugs as values. Because the dropdown is named after the taxonomy’s query variable, WordPress filters the list without any extra code.
The “all” option uses an empty value, so choosing it shows everything instead of searching for a term called “0”.
hierarchical check to include them.Open the list screen for a custom post type with a category-style taxonomy. A dropdown should appear next to the date filter.