Filtering Posts by Taxonomies in the Dashboard


By default, the admin Posts screen allows us to filter posts by the built-in “Categories” Taxonomy, using a neat, user-friendly dropdown menu. But in many cases, when we register new Taxonomies we often want to be able to filter posts by these new Taxonomies as well. In this quick tutorial, we will learn how to add new filters (dropdowns) to any Post Type screen in order to filter content by custom Taxonomies.


Filter WordPress Posts by Category
Filter WordPress Posts by Category

Registering a New Post Type and Taxonomies

For many WordPress developers this is a basic step, we do it in almost every project. Therefore, we won’t be getting into how to set it all up in your code — instead, use the following links to navigate to the snippets. You can use the Post Type Generator and the Taxonomy Generator to do that.

Ok, so in our example we will create a car catalog for an imaginary car retailer or agency. We will create a new “Car” post type and add several taxonomies (manufacturer, model, transmission, doors and color).


Cars Admin Screen
Cars Admin Screen

Adding Filters to the Post Type Admin Screen

Now that we have a working “Car” Post Type with several Taxonomies, we would like to be able to filter our cars in the admin area. For that we need to add filters (dropdowns) to help us sort our content and manage it easily.

By default, when we register new Taxonomies, WordPress does not add sorting filters to the admin area screen. However, developers are capable of doing that manually using the restrict_manage_posts action which fires just before the “Filter” button is printed out.

This much useful action has two parameters: The $post_type parameter accepts the Post Type’s slug and the $which parameter accepts the location of the navigation markup: ‘top’, ‘bottom’ (it also allows ‘bar’ for the Media screen).

For our example we will use the $post_type parameter to apply these filters only in the “Car” admin screen.


function filter_cars_by_taxonomies( $post_type, $which ) {

	// Apply this only on a specific post type
	if ( 'car' !== $post_type )

	// A list of taxonomy slugs to filter by
	$taxonomies = array( 'manufacturer', 'model', 'transmission', 'doors', 'color' );

	foreach ( $taxonomies as $taxonomy_slug ) {

		// Retrieve taxonomy data
		$taxonomy_obj = get_taxonomy( $taxonomy_slug );
		$taxonomy_name = $taxonomy_obj->labels->name;

		// Retrieve taxonomy terms
		$terms = get_terms( $taxonomy_slug );

		// Display filter HTML
		echo "<select name='{$taxonomy_slug}' id='{$taxonomy_slug}' class='postform'>";
		echo '<option value="">' . sprintf( esc_html__( 'Show All %s', 'text_domain' ), $taxonomy_name ) . '</option>';
		foreach ( $terms as $term ) {
				'<option value="%1$s" %2$s>%3$s (%4$s)</option>',
				( ( isset( $_GET[$taxonomy_slug] ) && ( $_GET[$taxonomy_slug] == $term->slug ) ) ? ' selected="selected"' : '' ),
		echo '</select>';

add_action( 'restrict_manage_posts', 'filter_cars_by_taxonomies' , 10, 2);

The Result

Now we have Taxonomy filters in our Cars admin screen, which allows us to display content that is assigned to the currently user-selected Taxonomies.


Filter Cars by Taxonomy
Filter Cars by Taxonomy

Hope this cool solution will help your clients manage their content!