Skip to content

Instantly share code, notes, and snippets.

@jchristopher
Created December 20, 2018 22:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jchristopher/6aae90c417ca380820eab33ebf25ce06 to your computer and use it in GitHub Desktop.
Save jchristopher/6aae90c417ca380820eab33ebf25ce06 to your computer and use it in GitHub Desktop.
Enable searching by post ID in the WordPress Admin using SearchWP
<?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