Product Categories in Search
-
Hello,
I’m trying to get our product categories to appear 1st in search. Right now they are not appearing at all.
Here’s what I’ve done/tried so far:
1. Re-Indexed with product_cat selected.2. Added this code from the User Manual to functions.php makes sure product_cat was in:
add_filter( 'relevanssi_modify_wp_query', 'rlv_include_product_cat' ); function rlv_include_product_cat( $query ) { if ( isset( $query->query_vars['product_cat'] ) ) { $query->query_vars['tax_query'][] = array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => $query->query_vars['product_cat'], 'include_children' => true, ); } return $query; }
3. Then added this to re-ordered search display:
add_filter('relevanssi_hits_filter', 'product_cat_first'); function product_cat_first($hits) { $types = array(); $types['page'] = array(); $types['post'] = array(); $types['product'] = array(); $types['product_cat'] = array(); // Split the post types in array $types if (!empty($hits)) { foreach ($hits[0] as $hit) { array_push($types[$hit->post_type], $hit); } } // Merge back to $hits in the desired order $hits[0] = array_merge($types['product_cat'],$types['product'],$types['page'], $types['post']); return $hits; }
Am I missing something?
Thanks in advance. 🙂
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Product Categories in Search’ is closed to new replies.