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

Brizy Pro
Brizy is another WordPress site builder and as usual, it too has hard-coded queries that don’t play nice with Relevanssi.…
Indexing HTML comments
By default, Relevanssi does not index HTML comments inside your posts. Relevanssi removes all HTML tags before indexing, and HTML…
Indexing product codes with and without spaces

A Relevanssi Premium customer had a problem with product codes. The codes are in the format “ABC 100”, a group of letters and digits with a space in between. Users may search for the codes without the space, so the post should be found with “ABC 100” or “ABC100”. The……product can be found with either “ABC 123” or “ABC123” search * terms. This is applied to post content and titles. * * @param string $content The content to manipulate. * * @return string The content with the spaceless product codes added. */ function rlv_product_codes( $content ) { $pattern =…

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