• Resolved JJ

    (@juliej82hotmailcom)


    Thanks for the great plugin.

    I have a term who name is for, example, Great Blue Trojans. The slug is GBT.

    I want to be able to search for ‘GBT’ and return all the posts with this term. When I search ‘Great Blue Trojans’ I get the hits. When I search GBT I do not.

    Is this as expected? Is there anything I could do to change if it is?

    https://wordpress.org/plugins/relevanssi/

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

    (@msaari)

    By default Relevanssi does not index the slug.

    Add this to your theme functions.php and rebuild the index, and you should be able to find posts by slug.

    add_filter('relevanssi_content_to_index', 'rlv_index_slugs', 10, 2);
    function rlv_index_slugs($content, $post) {
        $content .= ' ' . $post->post_name . ' ';
        return $content;
    }
    Plugin Author Mikko Saari

    (@msaari)

    Ah, misread your question; you were not talking about post slugs, but term slugs.

    This should do the trick, just add this to your theme functions.php and replace TAXONOMY with the name of the taxonomy you want to handle – “post_tag” for tags, “category” for categories and so on.

    add_filter('relevanssi_content_to_index', 'rlv_term_slugs', 10, 2);
    function rlv_term_slugs($content, $post) {
    	$tags = get_the_terms($post->ID, TAXONOMY);
    	if ($tags !== FALSE) {
    		$tagstr = "";
    		foreach ($tags as $tag) {
    			if (is_object($tag)) {
    				$content .= $tag->slug . ' ';
    			}
    		}
    	}
    }
    Thread Starter JJ

    (@juliej82hotmailcom)

    Awesome that worked (although I had to add return $content; before the last parentheses).

    Thanks!!!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘search term name and not slug?’ is closed to new replies.