add filter for post count query in WP_Posts_List_Table
|Reported by:||cardy_Web||Owned by:|
I've a custom post type "products" with a custom taxonomy "manufacturers"
I've hooked the parse_query filter when fired from edit.php because I've wanted to show posts based on current user criteria (user can edit only products belong to specific manufacturers).
Everything worked as expected, except for the post count in the table header that shows total amount of posts (not a filtered count).
Digging into the code I've found that inside WP_Posts_List_Table constructor (http://core.trac.wordpress.org/browser/trunk/wp-admin/includes/class-wp-posts-list-table.php#L59)the following code is performed:
$this->user_posts_count = $wpdb->get_var( $wpdb->prepare( " SELECT COUNT( 1 ) FROM $wpdb->posts WHERE post_type = %s AND post_status NOT IN ( 'trash', 'auto-draft' ) AND post_author = %d ", $post_type, get_current_user_id() ) );
I think that the simplest solution is to add a filter for the count query. By this way is possibile to customize the query that reflects the effective post count.