Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

restrict_manage_posts hook

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
add_action( 'restrict_manage_posts', 'my_post_type_filter', 10, 2 );
function my_post_type_filter( $post_type, $which ) {
    if ( 'my-post' !== $post_type ) {
        return; //check to make sure this is your cpt
    }
 
    $taxonomy_slug = 'my-post-type';
    $taxonomy      = get_taxonomy($taxonomy_slug);
    $selected      = '';
    $request_attr  = 'my_type'; //this will show up in the url
  
    if ( isset( $_REQUEST[ $request_attr ] ) ) {
        $selected = $_REQUEST[ $request_attr ]; //in case the current page is already filtered
    }
     
    wp_dropdown_categories(array(
        'show_option_all' =>  __("Show All {$taxonomy->label}"),
        'taxonomy'        =>  $taxonomy_slug,
        'name'            =>  $request_attr,
        'orderby'         =>  'name',
        'selected'        =>  $selected,
        'hierarchical'    =>  true,
        'depth'           =>  3,
        'show_count'      =>  true, // Show number of post in parent term
        'hide_empty'      =>  false, // Don't show posts w/o terms
    ) );
}
Source by developer.wordpress.org #
 
PREVIOUS NEXT
Tagged: #hook
ADD COMMENT
Topic
Name
4+9 =