2017-06-13 1 views
4

J'ai la recherche algolia qui fonctionne sur mon site mais dans le backend c'est aussi indexer un type de poste qui ne devrait jamais être indexé (car il contient des informations privées).Empêcher Algolia d'indexer certains types de postes

est-il un paramètre quelque part où je peux dire "NEVER index {} post_type"?

Répondre

8

Si vous parlez d'un plugin pour WordPress Algolia, vous pouvez certainement définir une fonction/crochet pour décider si un type de poste doit être indexé ou non.

Par exemple, vous pouvez écrire:

<?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); 

Vous pouvez en savoir plus sur: https://community.algolia.com/wordpress/indexing-flow.html#indexing-decision