How to search by drafts and planned

We enable administrators to search by drafts and scheduled entries.

If the filter doesn’t work, make sure no third party search plugins are enabled. They can replace the standard functionality and the filter will not work.

/ **
* Search all drafts planned
* /

add_action(‘pre_get_posts’, ‘searchFilter’);
function searchFilter($ query)
{
if (is_admin() ||
!current_user_can(‘activate_plugins’) ||
!$ query->is_main_query() ||
!$ query->is_search
) {
return;
}

$ query->set(‘post_status’, [‘publish’, ‘future’, ‘draft’]);
}

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *