• Resolved mmtrombl

    (@mmtrombl)


    Hello,

    I’d like to exclude content from being indexed for one specific post type only. Is there a way I can utilize relevanssi_index_content(); to do this? This filter seems to be global. Perhaps along the lines of:

    add_filter('relevanssi_index_content', 'contentoff');
    function contentoff() {
        if( get_post_type() == 'CPT' ) {
            return false;
        } else {
            return true;
        }
    }

    Although I know get_post_type() must be the wrong function to use here. Thanks.

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

    (@msaari)

    That’s almost there, but since relevanssi_index_content doesn’t pass the post ID and I’m not sure if it’s available from a global variable, that’s not going to work. But this should:

    add_filter('relevanssi_post_content', 'contentoff', 10, 2);
    function contentoff($content, $post) {
        if (get_post_type($post) == 'CPT') $content = "";
        return $content;
    }

    This filter is used to manipulate post content before Relevanssi sees it, so why not just wipe it all out…

    Thread Starter mmtrombl

    (@mmtrombl)

    Perfect, that’s it. Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Exclude Content for Custom Post Type’ is closed to new replies.