我正在使用的WordPress主题有一些自定义帖子类型作为aditional插件的一部分。这些帖子类型不适用于与Algolia索引。我可以添加它们以索引到searchable_posts索引吗?
我想这是插件中的相关代码:
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();
}
答案 0 :(得分: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;
}
}