I'm overriding WooCommerce's default search query to include searching by SKU as well.
// default search query
$query_default_search = new WP_Query(
array(
"post_type" => "product",
"s" => $search_query
)
);
// SKU query
$query_search_by_sku = new WP_Query(
array(
"post_type" => "product",
"meta_query" => array(
array(
"key" => "_sku",
"value" => $search_query,
"compare" => "LIKE"
)
)
)
);
If the default search query doesn't return any posts, I assume that an SKU has been entered and I run the SKU query. However, I want to merge both query arguments into one WP_Query call, rather than merging the results of both queries using array_merge.
If both queries had meta-query, I could use an OR relation, but this is different.
How can this be done?