Support » Plugin: Relevanssi - A Better Search » Category Description not found

  • Resolved staedeli


    Hi, thanks for creating such an awesome plugin.
    Your documentation says, that category description is indexed, so I understand it is searchable (

    I want to use the category description for synonyms, since I have 50+ categories. setup
    Category Name: God
    Category Description: Yahweh, Lord, Almighty

    If someone searches with any of these 4 terms, all posts with category God need to show up.
    Am I understanding something wrong? I indexed the category and rebuilt the index.
    If I search for God it works, but not with the terms in the description.

    I hope you can give me a clue what I’m missing? Thanks

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Mikko Saari


    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.


    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?

    Plugin Author Mikko Saari


    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

    Plugin Author Mikko Saari


    Good to hear it works; if you’re happy with the product and the service, please consider leaving a review.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Category Description not found’ is closed to new replies.