-
-
Save searchwpgists/7bff3dbdfb535e61632b879c0f1547f4 to your computer and use it in GitHub Desktop.
Search draft, private, and scheduled posts in admin side only
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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