Created
April 9, 2021 12:34
-
-
Save jchristopher/7c64436d32130e11c1b2b60b6d27cfec to your computer and use it in GitHub Desktop.
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 | |
// Allow searching by WP_Post ID. | |
function swp14237_searchwp_results( $results, $attributes ) { | |
$search_query = get_search_query(); | |
if ( ! is_numeric( $search_query ) ) { | |
return $results; | |
} | |
$the_post = get_post( absint( $search_query ) ); | |
if ( is_null( $the_post ) ) { | |
return $results; | |
} | |
array_unshift( $results, $the_post ); | |
return $results; | |
} | |
add_filter( 'searchwp\query\results', 'swp14237_searchwp_results', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment