Useful functions in Relevanssi

Relevanssi has some useful functions that can be helpful. Going through the source code looking for them is not fun, so here’s a list of all the functions that I think can be helpful used outside Relevanssi code.

These all are available in both free and Premium, unless noted otherwise. When using the functions, it’s always wise to wrap them in function_exists() block to avoid error messages when Relevanssi is for some reason deactivated:

if ( function_exists( 'name_of_the_function' ) ) {
    name_of_the_function( $parameter, $parameter );

Function documentation

Table of contents


Given a term id, the function returns the taxonomy of the term.

27 comments Useful functions in Relevanssi

  1. i can’t get the excerpt to display using get_excerpt or the relevanssi version of get_excerpt. all i get is […] and I’ve tried adding manual excerpts to a few posts tos ee if that would help, but no luck! Any ideas?

      1. No, which baffles me. Right now I’m using a sloppy fix to at least get *something* to show up… but it obviously doesn’t have the nice excerpts with the highlighted search terms like I was hoping for:

        1. I’d check to see if there’s something weird in your search results loop. Does the global $post get set properly? Try a var_dump($post) – do the post objects look good? If Relevanssi is creating excerpts as it should, there should be an excerpt in $post->post_excerpt.

  2. When i add product using php code not from wordpress dashboard. Then relevanssi doesn’t take this product it it’s search util i open the product page from dashboard and click on update button. How can i solve this problem ?

      1. Thank you for your encouragement, Mikko! The javascript addition has to be placed into the target page, right? Or is there a way to get it into the URL-link that gets me there? That would be fabulous for quotes to certain text passages, but this probably goes beyond Relevassi … Incidentally I still sometimes use “name” in my blooger blog and it keeps working.

        1. In order for the link to work, there would need to be an anchor on the result page. I suppose that’s possible as well, but it’s really up to your theme and not Relevanssi.

          1. Sorry, we are not able to do this, turns out, for “intellectual reasons” (too dumb). Might it not become standard to always move or scroll the result page to the highlight? I see no reason not to always do it. After all, the searcher wants to find exactly what she’s looking for, not the top of a page containing (for him just hopefully) the search clause? Thank you for considering.

          2. It’s not a standard feature, because it’s hard to do (as you’ve noticed) and requires things that can’t really be standardized and need to be done on per site basis.

            I also don’t think it’s always the correct thing to do – in most cases as a user I’d just get annoyed by this. I can use the browser on-page search, if I need to find a part of the page, but in general I’d prefer to read the page from the beginning.

          3. We are in a special situation, perhaps. We have 23 full books, each a single (!) web page, with all the texts of a lifetime of a defunct author ( Could you suggest me someone to help us in a paid effort? Private correspondence to Fritz@Joern.De is ok. I guess finding and spotting (scrolling to) must still be less of an effort, than to manually separate the pages into about thousand pieces. (I haven’t found search engines remembering “name” entry points to closer spot the target.) Here a special name marker (like the command to highlight something) would have to be plugged into the WordPress’ output page. (My dream would be browsers that can be told from the outside to search for a specific word in a page, so you could better reference something in a page … )

  3. Hi there! I’m using Relevanssi to boost the search of a wordpress site I’m developing. I managed Relevanssi to get search results for titles, contents, categories and tags. Then I was trying to highlight the terms for each situation. For the tags I saw there is a function called relevanssi_the_tags(), but it’s returning me the whole link of the tags as strings.

    So where there should be only the tag name, such as “Bangu”, the whole link is printed like “<a href=”http://localhost/pos2017/tag/bangu/” rel=”tag”>Bangu</a>“.

    Any clues on how to solve this?


    1. relevanssi_the_tags() is the equivalent of the WordPress default the_tags(), which does the same thing. If you want just a highlighted list of tags, get the tags somewhere else, put them in a string and then use relevanssi_highlight_terms() on that string.

      This should probably be fairly close to what you want: echo relevanssi_highlight_terms(get_the_tag_list(”, ‘, ‘), get_search_query());

      1. Yes. It worked! Doing this solved the problem:

        $tagList = strip_tags(get_the_tag_list(”,’, ‘,”));

        And then I’ve put $tagList as an argument inside relevanssi_highlight_terms() .

        Thank you so much for your help.

        Cheers! o/

    1. Richard, you need to edit your search results template. It’s likely using the_content() to print out the post content. Replace that with the_excerpt() to see excerpts.

  4. Please guide how can i show the search result if the searched word is in the last of the post.. By default the results starts with the first paragraph. if the word is in the last paragraph it is not shown in the result.

    1. Arlsan, Relevanssi should show the part of the post that has the searched term, whether that is in the first or the last paragraph. If you’re just seeing first paragraphs, make sure you have enabled Relevanssi-generated excerpts. If you have, and you’re still seeing the basic excerpts, make sure your theme is using the_excerpt() to show the excerpts.

  5. Using the free version of Relevanssi, where does the theme get altered so that search terms are highlighted in the results?

    1. Dave, as long as your theme is using the_excerpt() to print out the excerpt, the highlighting should work automatically. If it’s not, you need to edit the search results template (usually search.php).

  6. I have a long list of zip codes that I want to add to the plugin to return our locations page. Can I mass upload these or must I do this individually?

    1. Ryan, I don’t understand the question. What do you mean “mass upload”? If you plan to do this with redirects, then yes, you need to add the redirects individually, but you can also just add the zip codes to the post content and have Relevanssi index.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.