Alter query on edit.php

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 .)

Leave a Comment