prevent showing posts of an specific category in admin posts section

You can use the pre_get_posts action to affect any queries, both in frontend and admin. In your case you should make sure you affect only admin queries and you can even use get_current_screen to narrow it down further. Here’s an example that would modify the query only on the regular posts page:

add_action ('pre_get_posts', 'wpse311946_restrict_cats');
function wpse311946_restrict_cats ($query) {
   // retrieve the id of the category to be excluded
   $idObj = get_category_by_slug ('eventscat'); 
   $id = $idObj->term_id;
   // find current admin page
   $current_screen = get_current_screen ();
   // conditionally exclude category
   if (is_admin() && $current_screen->id == "edit-post" ) {
     $query->set ('cat', -$id);
     }
   }

You can use the same filter, slightly modified, to make sure only posts of this category are shown on the other posts page you want to create (this will have another screen id).

Leave a Comment