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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -