Modify WordPress Search

You could try something like this below. Basically, if we are performing a search and it is the main_query (the query that generates the page results) ignore the default search and perform an exact match via the query_where function custom_product_search_exact_match( $query ) { global $wpdb; if ( is_search() && is_main_query() && !empty( $query->query_vars[‘s’] ) ) … Read more

WP-Query and Searching Inside Arrays

For array and object meta values, WordPress serializes them to string representations using serialize(). Thus, your meta value looks like this in the database: a:3:{i:0;s:9:”1 | 1 | 1″;i:1;s:15:”1.5 | 1.5 | 1.5″;i:2;s:12:”22 | 22 | 22″;} There is no built-in way to query within these serialized strings, but since these are strings with a … Read more

WP Query: orderby with one meta key, but multiple values

Use this code instead- $supplierArgs = array( ‘post_type’ => ‘service_providers’, ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘key’ => ‘service_provider_tier’, ‘value’ => ‘G’, ‘compare’ => ‘=’ ), array( ‘key’ => ‘service_provider_tier’, ‘value’ => ‘S’, ‘compare’ => ‘=’ ), array( ‘key’ => ‘service_provider_tier’, ‘value’ => ‘B’, ‘compare’ => ‘=’ ), ), ‘orderby’ => ‘meta_value’, ‘meta_key’ => … Read more