Prevent Algolia indexing certain types of messages

I have an algolia search that runs on my site, but in the backend it also indexes the type of message that should never be indexed (since it contains private information).

Is there a parameter somewhere where I can say "NEVER index {post_type}"?

+4
source share
1 answer

If you are talking about the Algolia plugin for WordPress, you can definitely define the / hook function to decide whether to index the type of post or not.

For example, you could write:

<?php
/**
 * @param bool    $should_index
 * @param WP_Post $post
 *
 * @return bool
 */
function exclude_post_types( $should_index, WP_Post $post )
{
    if ( false === $should_index ) {
        return false;
    }

    // Add all post types you don't want to make searchable.
    $excluded_post_types = array( 'myprivatetype' );    
    return ! in_array( $post->post_type, $excluded_post_types, true );
}

// Hook into Algolia to manipulate the post that should be indexed.
add_filter( 'algolia_should_index_searchable_post', 'exclude_post_types', 10, 2 );

You can read more: https://community.algolia.com/wordpress/indexing-flow.html#indexing-decision

+8
source

Source: https://habr.com/ru/post/1679136/


All Articles