WordPress: adding category filter to custom built wp list table

I have created a custom wp list table which displays posts according to my custom WP_Query,
I need to implement a category filter like the one shown below.

enter image description here

Read More

I need to display all categories as a drop-down and on selecting a particular category, I want to somehow apply this category filter to my wp_query,
Here is my WP_Query.

$wp = new WP_Query(
    array("post_type" => "post", 
          "post_status" => $status, 
          "meta_key" => "sc_imported", 
          "meta_value" => true, 
          "posts_per_page" => $per_page, 
          "paged" => $current_page, 
          "orderby" => $_REQUEST['orderby'], 
          "order" => $_REQUEST['order'] 
         ));
  1. How to implement drop-down,
  2. how to apply this category filter to the WP_Query.

Related posts

Leave a Reply

1 comment

  1. Use this function wp_dropdown_categories( $args );. It will create dropdown for categories.

    <?php wp_dropdown_categories( $args ); ?> 
    <?php $args = array(
    'show_option_all'    => '',
    'show_option_none'   => '',
    'orderby'            => 'ID', 
    'order'              => 'ASC',
    'show_count'         => 0,
    'hide_empty'         => 1, 
    'child_of'           => 0,
    'exclude'            => '',
    'echo'               => 1,
    'selected'           => 0,
    'hierarchical'       => 0, 
    'name'               => 'cat',
    'id'                 => '',
    'class'              => 'postform',
    'depth'              => 0,
    'tab_index'          => 0,
    'taxonomy'           => 'category',
    'hide_if_empty'      => false
        'walker'             => ''
    ); ?> 
    

    Please read here for complete function details.