Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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