2017-09-12 8 views
0

1)特定のタクソノミーをアルゴリアに索引付けすることを排除しようとしています。私はこの仕事をすることはできません。これは私のコードです:Algolia - WordPress - インデクシングから複数のタクソノミーを除外する

function exclude_taxonomy($should_index_category, WP_Post $post) 
{ 
// Add all post types you don't want to make searchable. 
$excluded_event_categories = array(
'post_type' => 'events', 
'tax_query' => array(
    array(
     'taxonomy' => 'events_category', 
     'field' => 'slug', 
     'terms' => 'xclude', 
    ) 
), 

); 
if (false === $should_index_category) { 
    return false; 
} 

return ! in_array($post->taxonomy, $excluded_event_categories, true); 
} 

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

2)私は複数のタクソノミーでこれをどうやって行いますか?だから私は行く第二のものを持っている:

'tax_query' => array(
    array(
     'taxonomy' => 'events_status', 
     'field' => 'slug', 
     'terms' => 'archive', 
    ) 
), 

ありがとう。

答えて

0

私は問題が$excluded_event_categories変数の周りにあると思います。

あなたのコードは次のスニペットに似ているはずです。私が正しく理解していれば、events_categoryevent_categoryがインデックスから除外されます。

function exclude_taxonomy($should_index_category, WP_Post $post) 
{ 
    if (false === $should_index_category) { 
     return false; 
    } 

    return ! in_array($post->taxonomy, array('events_category', 'events_status'), true); 
} 

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

Julien Bourdeau - 複数の分類から複数の分類を除外する必要があります。だから私は 'events_status'タクソノミからアーカイブ用語を取り除く必要があり、 'events_category'分類から 'xclude'用語を取り除く必要があります。 – happyrobot

+0

このようなものでなければなりません: function custom_should_index_terms($ flag、WP_Post $ post){ $ excluded_ids = array(3795、1187); if(in_array($ post-> term_id、$ excluded_ids)){ falseを返します。 } return $ flag; } add_filter( 'algolia_should_index_post'、 'custom_should_index_terms'、10、2); add_filter( 'algolia_should_index_searchable_post'、 'custom_should_index_terms'、10,2); – happyrobot

+0

はい!あなたが正しいと思います。それは動作しましたか? –

関連する問題