2016-07-28 4 views
3

Algolia에서 특정 WordPress 페이지 카테고리의 색인이 생성되지 않도록하려면 어떻게합니까?Аlgolia - Wordpress - 색인 생성 카테고리 제외

+0

사용중인 플러그인의 버전을 알려주십시오. – rayrutjes

+0

현재 - 버전 0.1 버전 0.2.4를 사용해 보았습니다. -하지만 특정 카테고리를 제외 할 수는 없습니다 - 카테고리 만 일반으로 –

답변

5

우선, 새 버전의 플러그인을 계속 사용하는 것이 좋습니다. 이 글을 쓰는 시점에서 최신 버전은 0.2.5입니다. 실제로 이전 버전 (0.0.1)은 더 이상 지원되지 않습니다.

귀하의 질문에 관해서는, Algolia에 푸시하고 검색 가능한 게시물을 필터링 할 수 있습니다.

질문에서 알 수있는 것은 카테고리에 지정된 페이지가 있고 특정 카테고리의 페이지를 검색 결과에 표시하지 않으려는 것입니다. 이 초기 진술이 잘못 되었다면이 답변에 대해 의견을 말하십시오. 기꺼이 업데이트를 보내 드리겠습니다!

WordPress 필터를 사용하여 게시물의 색인 생성을 결정할 수 있습니다. 귀하의 경우, searchable_posts 색인에서 페이지를 제외 시키려면 algolia_should_index_searchable_post 필터를 사용할 수 있습니다. posts_page 색인에서 페이지를 제외하려면 algolia_should_index_post 필터를 사용할 수 있습니다.

다음은 ID로 식별되는 카테고리 목록의 모든 페이지를 제외 할 수있는 방법의 예입니다. 워드 프레스에 대한 Algolia 검색 플러그인을 확장에 대한

<?php 
    // functions.php of your theme 
    // or in a custom plugin file. 

    // We alter the indexing decision making for both the posts index and the searchable_posts index. 
    add_filter('algolia_should_index_post', 'custom_should_index_post', 10, 2); 
    add_filter('algolia_should_index_searchable_post', 'custom_should_index_post', 10, 2); 


    /** 
    * @param bool $should_index 
    * @param WP_Post $post 
    * 
    * @return bool 
    */ 
    function custom_should_index_post($should_index, WP_Post $post) { 
     // Replace these IDs with yours ;) 
     $categories_to_exclude = array(7, 22); 

     if (false === $should_index) { 
      // If the decision has already been taken to not index the post 
      // stick to that decision. 
      return $should_index; 
     } 

     if ($post->post_type !== 'page') { 
      // We only want to alter the decision making for pages. 
      // We we are dealing with another post_type, return the $should_index as is. 
      return $should_index; 
     } 


     $post_category_ids = wp_get_post_categories($post->ID); 
     $remaining_category_ids = array_diff($post_category_ids, $categories_to_exclude); 
     if (count($remaining_category_ids) === 0) { 
      // If the post is a page and belongs to an excluded category, 
      // we return false to inform that we do not want to index the post. 
      return false; 
     } 

     return $should_index; 
    } 

더 자세한 정보는에서 찾을 수 있습니다 documentation: Basics of extending the plugin 업데이트

:

코드는 꿀벌 그것을 경우 제품을 제외하지 않도록하기 위해 업데이트했습니다 여러 카테고리와 관련되어 있으며 모든 카테고리가 제외되지는 않습니다.

+0

감사합니다! 나는 0.2.8 버전을 다운로드하고 위의 코드를 내 테마의 functions.php에서 시도해 WordPress의 관리자 패널에서 다시 색인을 생성했다. Algolia에는 색인이 생성되지 않았다. –

+0

이 문제에 도움이 되셨습니까? - ID를 사용하여 위의 코드 (플러그인 파일에서)를 활성화하고 다시 색인을 생성 할 때 Algolia에는 전혀 색인이 생성되지 않습니다. –

+0

PHP 오류가 기록 되었습니까? – rayrutjes

관련 문제