Created
August 15, 2019 00:34
-
-
Save ccurtin/6113237066da2393450eba07d251d94a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
preg_match("/\d+(\.\d+)?x\d+(\.\d+)?/", $q, $new); | |
if ($new && $new[0]) { | |
$q = str_replace("x", " x ", $new[0]); | |
} | |
$args = array( | |
'posts_per_page' => 24, | |
'limit' => -1, | |
'paged' => $paged, | |
'post_status' => 'publish', | |
'post_type' => 'product_variation', | |
'meta_key' => '_price', | |
// 'order' => 'ASC', | |
// 'orderby' => 'meta_value_num title size_clause', | |
'orderby' => array( | |
'title' => 'ASC', | |
'size_clause' => ($size === 'lowest' || !$size ) ? 'ASC' : 'DESC', | |
'meta_value_num' => ($price === 'lowest' || !$price ) ? 'ASC' : 'DESC', | |
), | |
'post_parent' => $pc, | |
'sentence' => true, | |
's' => $q | |
); | |
$custom_query = new WP_Query($args); | |
if ($custom_query->found_posts == 0) { | |
unset($args['s']); | |
$args['meta_query'] = array( | |
'relation' => 'OR', | |
'size_clause' => array( | |
'key' => 'attribute_pa_size', | |
'value' => $q, | |
'compare' => 'LIKE' | |
), | |
// TODO::: Check if $q contains "mil" or "ml" and strip... | |
// TODO::: Save the search params in the URL to visually show correct dropdown values | |
// 'mil_clause' => array( | |
// 'key' => 'attribute_pa_mil', | |
// 'value' => $q, | |
// 'compare' => 'LIKE' | |
// ) | |
); | |
} | |
$custom_query = new WP_Query($args); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment