How to Include Draft and Private Posts in Admin Searches with SearchWP
SearchWP includes built-in support for improving search results in the WordPress admin area by enabling the Admin Engine option in the Engine Settings on the SearchWP Algorithms page. When this option is enabled, SearchWP enhances searches performed within the WordPress dashboard, such as searches in the Posts or Pages screens. However, by default, SearchWP only indexes and returns published content. Draft, private, and scheduled (future) posts are excluded from search results.
This behavior exists because SearchWP is primarily designed to power frontend search experiences, where unpublished content should not be publicly accessible. As a result, non-published post statuses are not indexed unless explicitly included. If you rely on SearchWP to search content in the admin area and need to locate draft, private, or scheduled posts, you can extend SearchWP’s behavior using a custom filter hook.
The following example demonstrates how to include draft, private, and scheduled posts in admin-only searches, while keeping frontend search results unchanged:
| <?php | |
| // Search draft, private, and scheduled posts in admin side only | |
| add_filter( 'searchwp\post_stati', function ( $post_stati, $args ) { | |
| $is_search = is_search() || isset( $_REQUEST['s'] ); | |
| $is_swp_search = isset( $_REQUEST['swps'] ); | |
| $is_admin = is_admin() && ! wp_doing_ajax(); | |
| // Do not modify post statuses on SearchWP results pages and normal frontend searches | |
| if ( ($is_swp_search || $is_search) && ! $is_admin ) { | |
| return $post_stati; | |
| } | |
| // Include draft, private, and scheduled (future) posts in admin search | |
| return array_unique( | |
| array_merge( $post_stati, [ 'draft', 'private', 'future' ] ) | |
| ); | |
| }, 20, 2 ); |
You can add this code using a code snippet plugin such as WPCode, or by preparing a SearchWP Customizations Plugin.
This hook modifies the list of post statuses that SearchWP considers during indexing and searching, but only when the search is performed in the WordPress admin area. As a result, draft, private, and scheduled posts from post types included in your SearchWP engine will become searchable in the dashboard. These posts will not appear in frontend search results, ensuring that unpublished content remains hidden from site visitors.

