Skip to content

Instantly share code, notes, and snippets.

@searchwpgists
Created December 30, 2025 15:59
Show Gist options
  • Select an option

  • Save searchwpgists/7bff3dbdfb535e61632b879c0f1547f4 to your computer and use it in GitHub Desktop.

Select an option

Save searchwpgists/7bff3dbdfb535e61632b879c0f1547f4 to your computer and use it in GitHub Desktop.
Search draft, private, and scheduled posts in admin side only
<?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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment