• Hello,

    i like your plugin, but i need to modify it.
    At the moment it indexes everything in the post content, that makes the search-results very incorrect.

    I want to only index the post title and the <h2></h2> tag in the post-content. Nothing else.

    How to realize that?

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

    (@msaari)

    The relevanssi_post_content filter hook lets you modify the post content before Relevanssi sees it. Just create a function that removes everything except the h2 tags.

    Something like this:

    add_filter('relevanssi_post_content', 'rlv_extract_h2');
    function rlv_extract_h2($content) {
        $count = preg_match_all('|<h2>.*?</h2>|U', $content, $matches);
        if ($count > 0) $content = implode(" ", $matches[0]);
        return $content;
    }
    Thread Starter davidschneider85

    (@davidschneider85)

    Hey,

    works perfect – much thanks!

    Thread Starter davidschneider85

    (@davidschneider85)

    Can you help me to extend the function to include everything in post content with <span>Content</span> too?

    Plugin Author Mikko Saari

    (@msaari)

    add_filter('relevanssi_post_content', 'rlv_extract_h2');
    function rlv_extract_h2($content) {
        $count = preg_match_all('|<(h2|span)>.*?</\1>|U', $content, $matches);
        if ($count > 0) $content = implode(" ", $matches[0]);
        return $content;
    }

    Something like this. Check that $matches[0] has all the matches, I’m not sure if that’s the case or not. But that’s the regex anyway.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Index post-title and content only’ is closed to new replies.