Continuing to research the question. There is a good example here, but there is a question of compatibility with live search
add_filter( 'posts_search', 'product_search_by_id', 9999, 2 );
function product_search_by_id( $search, $wp_query ) {
global $wpdb;
if ( is_admin() || ! is_search() || ! isset( $wp_query->query_vars['s'] ) || ( ! is_array( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] !== "product" ) || ( is_array( $wp_query->query_vars['post_type'] ) && ! in_array( "product", $wp_query->query_vars['post_type'] ) ) ) return $search;
$product_id = $wp_query->query_vars['s'];
if ( ! get_post( $product_id ) ) return $search;
$search = str_replace( 'AND (((', "AND (({$wpdb->posts}.ID IN (" . $product_id . ")) OR ((", $search );
return $search;
}
-
This reply was modified 1 year, 2 months ago by chadrex.