I'd like to transfor the following code. This code was done to add a specific search for post ID numbers. Now I need a function to extend the search to a meta field called "function_name", and the search is not public but from the admin post table
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' );
pre_get_posts
is an action, not a filter: changeadd_filter()
toadd_action()
and removereturn $query
.