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

    (@msaari)

    That is not quite correct. Relevanssi simply doesn’t highlight tags. It highlights search terms in post excerpts and post titles, but not in tags.

    You can make it highlight tags (or just about anything else), though. Relevanssi has a function called relevanssi_highlight_terms($string, $query) which you can use. Just put the post tags in a string and pass it with the search query to this function, and out comes the string with search terms highlighted.

    So, if your theme uses the_tags(); to display the post tags in the search results template, replace it with:

    echo relevanssi_highlight_terms(get_the_tag_list('', ', '), get_search_query());

    Hmm… actually, I think I’ll add relevanssi_the_tags() in the next version to do exactly this. Also, I think I need to write a user manual page on useful functions in Relevanssi.

    Thread Starter TDP'sGM

    (@gmhilltop)

    Thanks Mikko, but I am still am having a difficult time understanding and using PHP. I have no problem pasting code, and editing files, but what you just suggested just went a little over my head.

    I sort of understand what it is you suggested, but I don’t have the foggiest idea how to write that exactly.

    I think I’ll wait for you to update Relevanssi.

    It seems to me that if someone WANTED things highlighted, that it would make sense to highlight ALL the things that showed up in results. At least that way you can tell at a glance WHY that search result was pulled . . . even if it was from a Tag. It just makes sense to me.

    Thanks for your help.

    Plugin Author Mikko Saari

    (@msaari)

    Yes, but Relevanssi has no way of knowing what it is that you have showing up in your results. It doesn’t know what is in your search results template. Tags can be displayed in a number of ways – which one you’re using, Relevanssi can’t know. Using the relevanssi_highlight_terms() function you can add the highlights to anything you want, and Relevanssi doesn’t even have to know what it is.

    Anyway, I already added relevanssi_the_tags() function in Premium and the 3.0.6 version of free Relevanssi will get it as well. If you want to use it now, just copy this to your functions.php:

    function relevanssi_the_tags($sep = ', ', $echo = true) {
    	$tags = relevanssi_highlight_terms(get_the_tag_list('', $sep), get_search_query());
    	if ($echo) {
    		echo $tags;
    	}
    	else {
    		return $tags;
    	}
    }

    and replace the_tags() in your search results template with relevanssi_the_tags(). (This’ll cause you an error message when you update Relevanssi if you don’t remember to first delete this code from your functions.php.)

    Thread Starter TDP'sGM

    (@gmhilltop)

    Thanks for this. As I am still new to PHP (and wordpress for that matter) could you clarify this for me:

    Regarding the copy this to the functions.php file:

    function relevanssi_the_tags($sep = ', ', $echo = true) {
    	$tags = relevanssi_highlight_terms(get_the_tag_list('', $sep), get_search_query());
    	if ($echo) {
    		echo $tags;
    	}
    	else {
    		return $tags;
    	}
    }

    Do I just paste it in ANYWHERE within that file?

    … and in my “Search Results Template” . . . I have no idea where that is.

    Sorry for such a BASIC question, but the fact of the matter is I am still trying to figure out how wordpress file(s) interact with each other.

    When a post says “Search Results Template” and I don’t see a “Search Results Template” file anywhere, I hit a wall and it is frustrating.

    Quite frankly I find that my biggest problem with the whole codex section too. I try to implement something “Advance Custom fields” and it really isn’t clear what and where to put the code — the GIVE the code, but where to put it (EXACTLY), well that what I am struggling with.

    I realize that this is off topic now but, any suggestions would be greatly appreciated!

    Plugin Author Mikko Saari

    (@msaari)

    Anywhere, yes, just put it in the end.

    Search results template is in your theme files, usually search.php. However, the way this is actually done depends a lot from your theme.

    Thread Starter TDP'sGM

    (@gmhilltop)

    Thanks Mikko! The moment I have a chance I’ll give that a go.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Plugin: Relevanssi – A Better Search] Tags not being highlighted’ is closed to new replies.