2017-08-07 8 views
0

(WordPressのプラグイン)とポストを除外していますか?Algolia - ワードプレス - instantsearchページどのように私は、特定のIDを持つポストを除外する方法を特定のID Algoliaのinstantsearchページ

これはデフォルトのインスタント検索設定です。投稿IDを検索から除外するフィルタを追加するにはどうすればよいですか?フォルダにプラグインする

  var search = instantsearch({ 
       appId: algolia.application_id, 
       apiKey: algolia.search_api_key, 
       indexName: algolia.indices.searchable_posts.name, 
       urlSync: { 
        mapping: {'q': 's'}, 
        trackedParameters: ['query'] 
       }, 
       searchParameters: { 
        facetingAfterDistinct: true, 
     highlightPreTag: '__ais-highlight__', 
     highlightPostTag: '__/ais-highlight__' 
       } 
      }); 

答えて

4

唯一の良い解決策はないインデックス彼らにあります。 WordPressのAlgoliaプラグインと

インデックスは、ここでは詳細に説明されています。ここではhttps://community.algolia.com/wordpress/indexing-flow.html#indexing-decision

は、あなたが始める必要があるコードスニペットです:

<?php 
// to put in the functions.php file of your active theme. 
/** 
* @param bool $should_index 
* @param WP_Post $post 
* 
* @return bool 
*/ 
function exclude_post_ids($should_index, WP_Post $post) 
{ 
    // Add all post IDs you don't want to make searchable. 
    $excluded_ids = array(14, 66); 
    if (false === $should_index) { 
     return false; 
    } 

    return ! in_array($post->ID, $excluded_ids, true); 
} 

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

これが正解です。ありがとう、レイモンド! :) – happyrobot

-2

Goが>>クラスalgolia-search.php含ま

と、このコードそのコードは、このコードを追加し、正確に後

$query->set('post__in', $post_ids); 

を見つける

$query->set('post__not_in', array(1,2,3)); 

それから私に結果を教えてください。 私のコードで1,2,3はあなたが除外したい投稿IDです。結果の一部として記事を表示しないように おかげ

関連する問題