wordpress - Wordpress Algolia 插件,仅将所有帖子索引到 searchable_posts 索引中,而不是启用的?
问题描述
我刚刚开始使用 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 中那样拥有多个搜索自动完成/实例?
例如,用于搜索位置的不同页面和用于搜索服务的另一个页面。
解决方案
$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'
);
推荐阅读
- broadcast - omnet++ 从节点广播消息时出错
- visual-studio-code - 如何通过鼠标单击执行?
- swift - 符合协议的对象上的 Swift KVO
- ruby-on-rails - Rails 5,将参数传递给查询 - 它安全吗?
- javascript - 错误请求 400 将图像作为 base64 或 blob 发送到 MS Face Api、Angular 7
- asp.net - 由于实体类型'IdentityUserRole 上的'属性'xx',无法在数据库中播种表
' 有一个临时值 - laravel - Laravel 的 morphOne/morphTo 返回 null
- javascript - 在JS中的对象内过滤对象数组
- python - 如何在散景中做gridspec
- amp-html - `amp-list` 文档:src 属性中的 `<%host%>` URL 前缀是什么意思?