What’s the best way to alter the query being run on the Posts Edit screen (edit.php)?
The current method I’m using is by passing an argument to the global $wp_query like so:
$wp_query->query( array ('category__in' => array(14,9,2) ) );
However, this doesn’t really work as expected once the user pages back and forth, filters, or searches.
Few days ago I wrote a quick solution using pre_get_posts filter to hide some pages in admin area.
Maybe you could use it as a good starting point for whatever you’d like to achieve.
if ( is_admin() ) add_filter('pre_get_posts', 'mau_filter_admin_pages');
function mau_filter_admin_pages($query) {
$query->set('post__not_in', array(1,2,3) );
// Do not display posts with IDs 1, 2 and 3 in the admin area.
return $query;
}
But be careful: pre_get_posts
affects almost all post queries on your site. You will have to use some conditions to make it work only where desired. if (is_admin())
was enough for me, but like I said it was quick solution and I haven’t tested it properly yet.
Im sure some local wp ninja will correct this if it’s too dirty .)