php - Search by product color - WooCommerce -
i've been trying time figure out correct $args-array making custom search form, allowing user search products name, description , custom woocommerce attributes (as color).
is possible using wp_query @ or need alter built in search function? , if - how?
here's $args-options i've been trying now:
$args = array( 'posts_per_page' => 20, 'no_found_rows' => true, 'post_type' => array('product'), 'tax_query' => array( array( 'taxonomy' => 'oct-search', 'field' => 'slug', 'terms' => array($_post["search_string"]), ), ), );
okay, solved on own hand, using code:
$attributes = 'oct-shade'; $attributes = 'pa_'.$attributes; $filters = explode(',', $_post["search_string"]); $args = array( 'posts_per_page' => 20, 'no_found_rows' => true, 'post_type' => array('product'), 'tax_query' => array( 'relation' => 'or', array( 'taxonomy' => "$attributes", 'field' => 'slug', 'terms' => $filters, 'operator' => 'in' ), ), );
Comments
Post a Comment