add_action('restrict_manage_posts', 'filter_post_type_backend_by_taxonomies', 99, 2); function filter_post_type_backend_by_taxonomies($post_type, $which) { if( 'courses' !== $post_type) { return; } $taxonomies = array( 'coursecity' ); foreach( $taxonomies as $taxonomy_slug ) { $taxonomy_obj = get_taxonomy( $taxonomy_slug ); $taxonomy_name = $taxonomy_obj->labels->name; $terms = get_terms($taxonomy_slug); echo "<select name='{$taxonomy_slug}' id='{$taxonomy_slug}' class='postform'>"; echo '<option value="">' . sprintf( esc_html__( 'Show all %s', 'domain-name' ), $taxonomy_name) . '</option>'; foreach ( $terms as $term ) { printf( '<option value="%1$s" %2$s>%3$s (%4$s)</option>', $term->slug, ( ( isset( $_GET[$taxonomy_slug] ) && ( $_GET[$taxonomy_slug] == $term->slug ) ) ? ' selected="selected"' : '' ), $term->name, $term->count ); } echo '</select>'; } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter