Skip to main contentSkip to footer

Sometimes it is helpful to have Relevanssi index the taxonomy term descriptions for posts. For example, the term description can be a good place to add alternate search terms for the term. By default, Relevanssi only indexes the term name, so you need extra code to get the term descriptions.

The filter hook relevanssi_content_to_index is the tool for the job. It can be used to add extra content to posts as they are indexed. Add this function to your site (and replace post_tag with the name of the taxonomy you want to use):

add_filter( 'relevanssi_content_to_index', function( $content, $post ) {
	$terms = get_the_terms( $post->ID, 'post_tag' );
	if ( is_array( $terms ) ) {
		foreach ( $terms as $term ) {
			$content .= ' ' . $term->description;
		}
	}
	return $content;
}, 10, 2);

When you rebuild the index, the term descriptions are indexed for all the posts that have that term.

Your account

Not logged in. Log in to see your license details.

Search

Popular Resources

Issues with post order plugins

…then you may be using a plugin that affects the post order. One example is Intuitive Custom Post Order, which reorders posts – and the Relevanssi results. The fix is simple, though. Add this function to your site: add_filter( ‘relevanssi_orderby’, function ( $orderby ) { return array( ‘relevance’ => ‘desc’ );…

WooCommerce: Aelia Prices by Country product visibility

…$post = get_post( $post_id ); $post_type = $post->post_type; $product_id = $post->ID; if ( ‘product‘ === $post_type && function_exists( ‘wc_get_product’ ) ) { // Get the product object. $product = wc_get_product( $product_id ); // Check if the product is purchasable. if ( $product && ! $product->is_purchasable() ) { $post_ok = false;……Check if the product is purchasable. if ( $product && ! $product->is_purchasable() ) { $post_ok = false; } } return $post_ok; } This function uses the relevanssi_post_ok filter hook to control which posts are included in the search and the $product->is_purchasable() function to see if the product can be shown….Aelia has a Prices by Country for WooCommerce plugin, which can adjust prices based on customer country and hide products unavailable in a specific country. Jason James shared a function that makes Relevanssi hide unavailable products in search: add_filter( ‘relevanssi_post_ok’, ‘relevanssi_aelia_compatibility’, 10, 2 ); function relevanssi_aelia_compatibility( $post_ok, $post_id ) {…

Related Posts:

Comment Section:

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed