Created
December 20, 2018 22:12
-
-
Save jchristopher/6aae90c417ca380820eab33ebf25ce06 to your computer and use it in GitHub Desktop.
Enable searching by post ID in the WordPress Admin using SearchWP
This file contains 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 | |
add_filter( 'searchwp_results', function( $results, $args ) { | |
if ( ! is_admin() ) { | |
return $results; | |
} | |
if ( count( $args['terms'] ) > 1 ) { | |
return $results; | |
} | |
if ( is_numeric( $args['terms'][0] ) ) { | |
$maybe_post = get_post( absint( $args['terms'][0] ) ); | |
if ( ! empty( $maybe_post ) ) { | |
$results = array_merge( | |
array( $maybe_post ), | |
$results | |
); | |
} | |
} | |
return $results; | |
}, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment