WordPress at a glance
function is not described

WP_Posts_List_Table::categories_dropdown() protected WP 4.6.0

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

This is a method of the class: WP_Posts_List_Table{}

Hooks from the method
Return

Null. Nothing.

Usage

// protected - for code of main (parent) or child class
$result = $this->categories_dropdown( $post_type );
$post_type(string) (required)
Post type slug.

Notes

  • Global. Int. $cat Currently selected category.

Changelog

Since 4.6.0 Introduced.

Code of WP Posts List Table::categories dropdown: wp-admin/includes/class-wp-posts-list-table.php WP 5.4.2

<?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">' . __( 'Filter by category' ) . '</label>';
		wp_dropdown_categories( $dropdown_options );
	}
}