Skip to content

Instantly share code, notes, and snippets.

@msaari
Created November 2, 2019 03:35
Show Gist options
  • Save msaari/f9d3bfb96cbefaa62f329bab5a3356c3 to your computer and use it in GitHub Desktop.
Save msaari/f9d3bfb96cbefaa62f329bab5a3356c3 to your computer and use it in GitHub Desktop.
Relevanssi product category pinning
<?php
/**
* This will lift all the product categories in the results on top of the results.
*/
add_filter( 'relevanssi_hits_filter', 'rlv_lift_category', 20 );
function rlv_lift_category( $hits ) {
$categories = array();
$other_posts = array();
foreach ( $hits[0] as $hit ) {
if ( 'product_category' === $hit->post_type ) {
$categories[] = $hit;
} else {
$other_posts[] = $hit;
}
}
$hits[0] = array_merge( $categories, $other_posts );
return $hits;
}
/**
* This function is used to add the extra keywords to the category pages.
*/
add_filter( 'relevanssi_tax_term_additional_content', 'rlv_add_terms', 10, 2 );
function rlv_add_terms( $content, $term ) {
if ( 'Premium Mattresses' === $term->name ) {
$content .= 'mattress collection';
}
return $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment