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

Redirecting email searches to the login page

A client asked for a solution to redirect all searches for email addresses to the login page – perhaps someone is constantly using the search field when they’re actually looking for the login. This can be achieved with the Redirects tool, as it takes regular expressions. You can also add this……to your site: add_action( ‘template_redirect’, ‘rlv_redirect_emails’ ); function rlv_redirect_emails() { if ( filter_var( get_search_query(), FILTER_VALIDATE_EMAIL ) ) { if ( wp_redirect( ‘https://www.example.com/wp-login.php’ ) ) { exit(); } } } This function would redirect all queries that look like email addresses (based on RFC 822, with some caveats) to the login……) ) { exit(); } } } This function would redirect all queries that look like email addresses (based on RFC 822, with some caveats) to the login page on example.com. There’s nothing Relevanssi-specific about this, this same function will work with any search solution that isn’t an AJAX search….

Search is ignoring accents
In general, searches ignore accents, which is generally a good idea: for example in French, the difference between e and…
Integrating Post Views Counter stats
It’s possible to integrate all kinds of external data to Relevanssi weights. Post Views Counter is an analytics plugin that collects stats…

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