2017-01-18 39 views
0

我正在使用的WordPress主題有一些自定義帖子類型,作爲aditional插件的一部分。這些帖子類型不適用於Algolia索引。我可以將它們添加到searchable_posts索引中嗎?爲Algolia索引添加自定義帖子類型

我想這是在插件的相關代碼:

private function init() { 

     $this->setup_constants(); 

     // Actions 
     add_action('plugins_loaded', array($this, 'load_languages'), 11); 
     add_action('init', array($this, 'init_settings'), 99); 
     add_action('init', array($this, 'register_post_type'), 100); 
     add_action('init', array($this, 'register_taxonomies'), 101); 
     add_action('add_meta_boxes', array($this, 'add_meta_boxes_function')); 
     add_action('pre_post_update', array($this, 'pre_post_update_function'), 10, 2); 
     add_action('save_post', array($this, 'save_meta_box_data')); 
     add_action('edit_form_after_title', array($this, 'add_meta_box_after_title')); 
     add_action('admin_menu', array($this, 'change_destination_menu')); 
     add_action('edit_form_top', array($this, 'edit_form_top_func'));   // need to tabs output 
     add_action('pre_get_posts', array($this, 'sort_destinations_by_meta_value')); 
     add_action('wp_footer', array($this, 'language_switcher_fix')); 

     // Filters 
     add_filter('template_include', array($this, 'para_destination_templates')); 
     add_filter('request', array($this, 'alter_the_query')); 
     add_filter('wp_title', array($this, 'page_name_wp_title'), 10, 2); 
     add_filter('wp_link_query', array($this, 'wp_link_query_destination'), 10, 2); 

     add_filter('oembed_discovery_links', array($this, 'oembed_discovery_links_rf'), 10, 2); 
     add_filter('previous_post_rel_link', array($this, 'previous_post_rel_link_rf')); 
     add_filter('next_post_rel_link', array($this, 'next_post_rel_link_rf')); 

     add_filter('wp_get_nav_menu_items', array($this, 'fix_menu_url_info_pages'), 10, 3); 
     add_filter('preview_post_link', array($this, 'fix_preview_link')); 
     // WP Init 
     add_action('init', array($this, 'load_scripts')); 

     // Settings 
     $this->settings = get_destination_settings(); 

     // Create objects 
     $this->master = new Travel_Master_Pages_CPT($this->settings); 
     $this->list = new Travel_Directory_CPT($this->settings); 
     $this->map = new Destination_Maps($this->settings, false); 

     // Compatibility 
     $this->backward(); 

    } 

回答

3

默認情況下,搜索的職位指數將包含從搜索中排除未舉報的所有日誌類型。

這裏是我們用來獲取這些確切的代碼行:

$searchable_post_types = get_post_types(array('exclude_from_search' => false), 'names'); 

索引文章類型的唯一方法是被排除在搜索,以確保該職位類型不是從搜索中排除了:

<?php 

// functions.php 

add_action('init', 'update_my_custom_type', 99); 

function update_my_custom_type() { 
    global $wp_post_types; 

    if (post_type_exists('my-custom-type')) { 

     // exclude from search results 
     $wp_post_types['my-custom-type']->exclude_from_search = false; 
    } 
} 
+0

這些帖子類型未被標記或從搜索中排除。當我停用Algolia插件時,它們確實出現在搜索結果中。 functions.php的代碼不起作用。 – CannedBear

+0

你介意分享帖子類型是如何註冊的嗎?我認爲問題在於,主題可能只會在帖子類型中添加一些可能在索引期間不會觸發的掛鉤。 – rayrutjes

+0

嗨rayrutjes,我添加到原來的帖子,我認爲可能是相關的代碼。 – CannedBear

相關問題