WP_Media_List_Table::media_categories_dropdown( string $post_type )

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


Parameters

$post_type

(Required) Post type slug.


Source

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

	public function media_categories_dropdown( $post_type ) {

		/**
		 * Filters whether to remove the 'Media Categories' drop-down from the media list table or grid.
		 *
		 * @since CP-2.2.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_media_categories_dropdown', false, $post_type ) ) {
			return;
		}

		$media_category = get_taxonomy( 'media_category' );
		if ( is_object_in_taxonomy( 'attachment', 'media_category' ) ) {
			$dropdown_options = array(
				'show_option_all' => $media_category->labels->all_items,
				'hide_empty'      => 0,
				'hierarchical'    => 1,
				'show_count'      => 0,
				'orderby'         => 'name',
				'name'            => 'taxonomy=media_category&term',
				'taxonomy'        => 'media_category',
				'selected'        => get_query_var( 'term' ),
				'value_field'     => 'slug',
			);

			echo '<label class="screen-reader-text" for="cat">' . $media_category->labels->filter_by_item . '</label>';

			wp_dropdown_categories( $dropdown_options );
		}
	}


Changelog

Changelog
Version Description
CP-2.2.0 Introduced. CP-2.2.0