Yes and no: Relevanssi indexes category description, but only for the categories themselves, which requires Relevanssi Premium. The category description is not indexed for the posts in the category.
With the free version, you need some filtering in order to make this work. You can use the relevanssi_content_to_index filter hook to add any content you want to to the posts before they are indexed, so you can write a function that will fetch all categories for the post and adds their descriptions to the post content.
If you’re using OR search, you can also add those synonyms in Relevanssi synonyms settings, that works as well.
Mikko,
Thanks for your clear answer.
If I buy the premium version I still need to write a function to achieve my goal?
I’m using Toolset and they referred me to you. I wouldn’t know how to write such a function…
I have a couple hundred synonyms in this download site. There are several drop downs to restrict search and then a text field to restrict even further. is this the AND / OR search you are referring to?
https://selk2.stadeli.com/beitrage/
Yes, you’d have to, because with Premium, you still wouldn’t get all the posts: if you indexed the taxonomy terms, then searching for “Almighty” would return the category “God”, not the posts in the category. In order to find posts by the category description, you need the filter function.
Here’s the filter function you need:
add_filter( 'relevanssi_content_to_index', 'rlv_category_desc', 10, 2 );
function rlv_category_desc( $content, $post ) {
$categories = get_the_terms( $post->ID, 'category' );
$descs = array_map( function ( $cat ) { return $cat->description; }, $categories );
$content .= implode( ' ', $descs );
return $content;
}
Add this to your theme functions.php and rebuild the index.
Mikko you’re my hero, the script works!!
Since registered users can add posts to this site in the future, does the index to be rebuild every day so it will add those category descriptions to the posts as well? Or can I automate it?
New posts work as well, no need to re-index every time. Thanks again for your professional help!
closing this question as resolved
Good to hear it works; if you’re happy with the product and the service, please consider leaving a review.