首页 > 解决方案 > Wordpress Algolia 插件,仅将所有帖子索引到 searchable_posts 索引中,而不是启用的?

问题描述

我刚刚开始使用 Wordpress Algolia - 并且已经阅读了初始文档。

我遇到的问题是我有几种帖子类型,但只想让其中一种可搜索,那就是locationCPT。

1)在自动完成设置中,我启用“位置”复选框,没有别的,点击保存。

2)插件请求索引该帖子类型,但最终索引/推送所有帖子类型。

不确定这是否与我添加 CPT 的方式有关?这是我使用的代码 - 我只粘贴了一个 CPT,但它们都遵循相同的结构:

add_action( 'init', 'register_cpt_location',0 );

function register_cpt_location() {

    $labels = array(
        'name'                  => _x( 'Locations', 'location' ),
        'singular_name'         => _x( 'Location', 'location' ),
        'add_new'               => _x( 'Add New', 'location' ),
        'add_new_item'          => _x( 'Add New Location', 'location' ),
        'edit_item'             => _x( 'Edit Location', 'location' ),
        'new_item'              => _x( 'New Location', 'location' ),
        'view_item'             => _x( 'View Location', 'location' ),
        'search_items'          => _x( 'Search Locations', 'location' ),
        'not_found'             => _x( 'No locations found', 'location' ),
        'not_found_in_trash'    => _x( 'No locations found in Trash', 'location' ),
        'parent_item_colon'     => _x( 'Parent Location:', 'location' ),
        'menu_name'             => _x( 'Locations', 'location' ),
    );

    $args = array(
        'labels'                => $labels,
        'hierarchical'          => true, // True to allow for sub-pages
        'supports'              => array( 'title', 'editor' ),
        'menu_icon'             => 'dashicons-location',
        'public'                => true,
        'show_ui'               => true,
        'show_in_menu'          => true,
        'menu_position'         => 4,
        'show_in_nav_menus'     => false,
        'publicly_queryable'    => true,
        'exclude_from_search'   => false,
        'has_archive'           => true,
        'query_var'             => true,
        'can_export'            => true,
        'rewrite'               => true,
        'capability_type'       => 'post'
    );

    register_post_type( 'location', $args );
} 

任何帮助表示赞赏,所以我可以继续前进!

我遇到的第二个问题 - 是否可以像 SearchWP 中那样拥有多个搜索自动完成/实例?

例如,用于搜索位置的不同页面和用于搜索服务的另一个页面。

标签: wordpressalgolia

解决方案


$args = array(
        'labels'                => $labels,
        'hierarchical'          => true, // True to allow for sub-pages
        'supports'              => array( 'title', 'editor' ),
        'menu_icon'             => 'dashicons-location',
        'public'                => true,
        'show_ui'               => true,
        'show_in_menu'          => true,
        'menu_position'         => 4,
        'show_in_nav_menus'     => false,
        'publicly_queryable'    => true,

'exclude_from_search' => 假,

    'has_archive'           => true,
    'query_var'             => true,
    'can_export'            => true,
    'rewrite'               => true,
    'capability_type'       => 'post'
);

推荐阅读