【发布时间】:2019-02-26 16:36:18
【问题描述】:
我刚刚开始使用 Wordpress Algolia - 并且已经阅读了初始文档。
我遇到的问题是,我有几种帖子类型,但只想让其中一种可搜索,那就是location CPT。
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 中那样拥有多个搜索自动完成/实例?
例如,搜索位置的不同页面和搜索服务的另一个页面。
【问题讨论】:
-
'exclude_from_search' => 对,
-
我没想到,应该有。谢谢先生。