I need to "hide" some old posts from the I decided to go with a custom post status to keep them hidden but available at a later time (keeps the admin cleaner..) BUT :)

I would like to have the posts with this status searchable but not available with the other filter-links like this ("Archived (2)") should not be in this list...

All (97) | Published (95) | Drafts (12) | Archived (2) |Private (2) | Trash (1)|

I register the post status with these parameters...

'public' => false,
'internal' =>true,
'exclude_from_search' => false,
'show_in_admin_all_list' => false,
'show_in_admin_status_list' => true,

But with these settings, the menu element is visible, and if I do

'show_in_admin_status_list' => false,

The posts with "archive" status is not searchable.

I'm using a modified version from this answer (see "PostStatusExtender" ) (changed name and post type)

New post status for custom post type

Any ideas how to solve this one?

  • What do you mean by "searchable"? Jun 18, 2018 at 16:32
  • Searchable in admin (using the search field to the right above the post list). These posts should only be available in admin - but not in a "statustype" list as I tried to describe in my original post.
    – Leif S.
    Jun 18, 2018 at 17:40

1 Answer 1


You can filter your admin query with pre_get_posts filter.

function wpse_306361_admin_search($query) {
    if(is_admin() && $query->is_main_query() && $query->is_search()) {
        $query->set('post_status', array('publish', 'draft', 'what-you-want', 'your_custom_status'));
    return query;
add_action('pre_get_posts', 'wpse_306361_admin_search', 10, 1);

It will check if query is in admin, if it's main query and if it's a search query.

If it's only for a post_type, don't forget to add a condition in your if statement.

pre_get_posts on codex : https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts

  • For some reason, the $query->is_admin() did not work, even if it shows "true" in the dump (checked $query by dumping it to error_log). I changed that part of the if statement to "is_admin()" . And the post_statuses changed to my prefs. And voilá. It works :) Thank you!
    – Leif S.
    Jun 19, 2018 at 6:54
  • My bad for $query->is_admin(), you're right ! is_admin() must be use here instead of $query->is_admin()
    – Elex
    Jun 19, 2018 at 10:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.