Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ccurtin/6113237066da2393450eba07d251d94a to your computer and use it in GitHub Desktop.
Save ccurtin/6113237066da2393450eba07d251d94a to your computer and use it in GitHub Desktop.
<?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