Custom search by attributes only
-
I am creating a custom search on front page only for attributes. Can someone direct me in right way? I am still a newbie and I got stuck :/
Search form is sending url as
?s=&post_type=product&color=blue
// Woo attributes $woo_atts = array('color', 'depth', 'length'); // set query vars function themeslug_query_vars( $qvars ) { global $woo_atts; foreach($woo_atts as $att) $qvars[] = $att; return $qvars; } add_filter( 'query_vars', 'themeslug_query_vars' , 10, 1 ); // search query vars add_action('pre_get_posts', 'woo_search_pre_get_posts'); function woo_search_pre_get_posts($query){ if ( is_search() ) { global $woo_atts; foreach($woo_atts as $att) : if(get_query_var($att)) : $meta_query[] = array( 'key' => 'pa_'.$att, 'value' => get_query_var($att), 'compare' => 'LIKE', ); $query->set('meta_query', $meta_query); endif; endforeach; } }
Is this even the right approach? Both key and values are correctly set but I don’t get any results
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Custom search by attributes only’ is closed to new replies.