WP_Posts_List_Table::categories_dropdown() WordPress Method

The WP_Posts_List_Table::categories_dropdown() method displays a categories dropdown for the posts list table. This can be useful for quickly filtering the list table by category.

WP_Posts_List_Table::categories_dropdown( string $post_type ) #

Displays a categories drop-down for filtering on the Posts list table.


Parameters

$post_type

(string)(Required)Post type slug.


Top ↑

Source

File: wp-admin/includes/class-wp-posts-list-table.php

	protected function categories_dropdown( $post_type ) {
		global $cat;

		/**
		 * Filters whether to remove the 'Categories' drop-down from the post list table.
		 *
		 * @since 4.6.0
		 *
		 * @param bool   $disable   Whether to disable the categories drop-down. Default false.
		 * @param string $post_type Post type slug.
		 */
		if ( false !== apply_filters( 'disable_categories_dropdown', false, $post_type ) ) {
			return;
		}

		if ( is_object_in_taxonomy( $post_type, 'category' ) ) {
			$dropdown_options = array(
				'show_option_all' => get_taxonomy( 'category' )->labels->all_items,
				'hide_empty'      => 0,
				'hierarchical'    => 1,
				'show_count'      => 0,
				'orderby'         => 'name',
				'selected'        => $cat,
			);

			echo '<label class="screen-reader-text" for="cat">' . get_taxonomy( 'category' )->labels->filter_by_item . '</label>';

			wp_dropdown_categories( $dropdown_options );
		}
	}


Top ↑

Changelog

Changelog
VersionDescription
4.6.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.