Skip to content

Instantly share code, notes, and snippets.

@drivendevelopment
Last active January 14, 2025 15:38
Show Gist options
  • Save drivendevelopment/72c4abfde8b758d4789e3d1258a26801 to your computer and use it in GitHub Desktop.
Save drivendevelopment/72c4abfde8b758d4789e3d1258a26801 to your computer and use it in GitHub Desktop.
<?php
/**
* Tweaks the query used for finding pages in the menus area so that if a number
* is entered in the search field, the query will look for a post with that ID
* instead of searching by the number.
*/
add_action( 'parse_query', function( $query ) {
// Only apply this to the menu quick search
if ( isset( $_POST['action'] ) && 'menu-quick-search' == $_POST['action'] ) {
// Only apply if a number was entered
if ( ! empty( $_POST['q'] ) && is_numeric( $_POST['q'] ) ) {
$query->set( 'p', $_POST['q'] );
$query->set( 's', '' );
}
}
return $query;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment