[wp-trac] [WordPress Trac] #23501: add filter for post count query in WP_Posts_List_Table
WordPress Trac
noreply at wordpress.org
Mon Feb 18 14:02:40 UTC 2013
#23501: add filter for post count query in WP_Posts_List_Table
-----------------------------+----------------------------
Reporter: cardy_Web | Type: enhancement
Status: new | Priority: normal
Milestone: Awaiting Review | Component: Administration
Version: trunk | Severity: normal
Keywords: |
-----------------------------+----------------------------
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.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/23501>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list