WP_Post_List_Table::get_views – Have post counts account for filters?

You might want to remove those counts and replace them with your own.

function insert_post_counts($views){
    //Run your query to count posts
    //use wp_cache_set and wp_cache_get to optimize performance

    $edit_url = admin_url( 'edit.php' );

    $views['all'] = 'All <a href="'.$edit_url.'">('.$all_count.')</a>';
    $views['publish'] = 'Published <a href="'.$edit_url.'?post_status=publish">('.$publish_count.')</a>';
    $views['draft'] = 'Draft <a href="'.$edit_url.'?post_status=draft">('.$draft_count.')</a>';
    $views['trash'] = 'Trash <a href="'.$edit_url.'?post_status=trash">('.$draft_count.')</a>';

    return $views;
}
add_filter('views_edit-post, 'insert_post_counts', 10, 1);

You can reference how wp_count_posts works to generate the native post counts.

Hope this helps!

Leave a Comment