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?
1 Answer
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