Woocommerce search product based on attributes

I have the simple products having the attributes like color: red, from year: 1988, to year:1994, etc.

I have created search form that search the product based on the parameter selected in form’s drop down.

Read More

The form contain two drop down. 1-Color, 2-Year.

I have the problem with year attributes. The functionality would be like when users select the year (for example 1990) from the drop down then it should return all the products whose “From Year” value less then selected value(1990) and “To Year” value is greater than selected value(1990).

That means selected value must be between products from year and to year.
Please help me to write meta query that return the products list as describe above.

'meta_query' => array( 
                  array( 'relation'=> 'AND' ), 
                  array( 'key' => '_product_attributes', 
                         'value' => red, 
                         'compare' => 'like'),
                  ),

Related posts

Leave a Reply