我有一个CPT,其中转发器字段的字段类型为“用户”。 我用它来标记文章的用户。 用户执行搜索时,CPT搜索工作正常,但不检查创建的元字段“用户”。 我要包括此内容,即搜索已被标记的用户。 检查了文档并发现以下内容:
还启用并建立了索引: 索引名称:posts_acf-field 索引名称:posts_acf-field-group。
同时,检查了该帐户,发现此字段已添加到仪表板中,因此这可能与未在结果页面中显示和自动完成有关。 这是我要添加到搜索和列表中的代码
//添加可搜索的自定义字段
add_filter( 'algolia_post_shared_attributes', 'my_event_attributes', 10, 2 );
add_filter( 'algolia_searchable_post_shared_attributes', 'my_event_attributes', 10, 2 );
function my_event_attributes( array $attributes, WP_Post $post ) {
if ( 'poker-news' !== $post->post_type ) {
return $attributes;
}
$repeater = get_field( 'tag_users', $post->ID );
$x = 0;
foreach ($repeater as $item) {
$attributes['tag_users'][$x] = $item;
$x = $x + 1;
}
return $attributes;
}
//使自定义字段可搜索
add_filter( 'algolia_posts_speaker_index_settings', 'my_posts_index_settings' );
function my_posts_index_settings( array $settings ) {
$settings['attributesToIndex'][] = 'unordered(tag_users)';
$settings['attributesToSnippet'][] = 'tag_users:50';
return $settings;
}
有人可以帮助我如何包括对转发器字段或任何参考链接的搜索吗?我相信这是问题所在:
$settings['attributesToIndex'][] = 'unordered(tag_users)';
$settings['attributesToSnippet'][] = 'tag_users:50';