they doesnt work, but I already have a couple of functions for the search, in order to add a specific search for the posts code:
function search_by_post_id($query) {
if($query->is_search) {
if(is_numeric($query->query_vars['s'])) {
$query->set('post_type', 'any');
$query->set('post__in', array((int)$query->query_vars['s']));
$query->set('s', '');
}
}
return $query;
}
add_filter('pre_get_posts', 'search_by_post_id');
/**
* Add search custom posts by their ID in WordPress dashboard
*
*/
add_action( 'parse_request', 'cdxn_search_by_id' );
function cdxn_search_by_id( $wp ) {
global $pagenow;
if( !is_admin() && 'edit.php' != $pagenow && 'post' !== $_GET['post_type']) {
return;
}
// If it's not a search return
if( !isset( $wp->query_vars['s'] ) ) {
return;
}
// Validate the numeric value
$id = absint( substr( $wp->query_vars['s'], 0 ) );
if( !$id ) {
return;
}
unset( $wp->query_vars['s'] );
$wp->query_vars['p'] = $id;
}