How to add new tab to admin list of posts and handle result list



add_action('views_edit-post','remove_edit_post_views');function remove_edit_post_views( $views ){
    $views['pre']='<a href="'.admin_url().'edit.php?pre=pre">My Special Posts</a>';return $views;}

add_action('pre_get_posts','my_special_list');function my_special_list( $q ){
  $scr = get_current_screen();if( is_admin()&&( $scr->base==='edit')&& $q->is_main_query()){// To target only a post type uncomment following line and adjust post type name// if ( $scr->post_type !== 'post' ) return;// if you change the link in function above adjust next line accordingly
    $pre = filter_input(INPUT_GET,'pre', FILTER_SANITIZE_STRING);if( $pre ==='pre'){// adjust meta query to fit your needs
      $meta_query = array('key'=>'is_special','value'=>'yes',);
      $q->set('meta_query', array($meta_query));}}}

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s