【发布时间】:2017-12-09 08:31:15
【问题描述】:
我正在尝试将 ACF 字段索引为自定义属性。根据 Algolia 文档 (https://community.algolia.com/wordpress/advanced-custom-fields.html),我设法索引了简单的 ACF 字段。我还设法索引了中继器字段,但我不确定这是否是最好的方法。有没有人设法解决了这个问题,并且不仅能够索引 ACF 转发器字段,而且后来在 WordPress 网站上搜索时将它们拉到 Instantsearch 模板上?
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 ( 'events' !== $post->post_type ) {
return $attributes;
}
$attributes['description'] = get_field( 'event_description', $post->ID );
$attributes['time'] = get_field( 'event_time', $post->ID );
$attributes['date'] = get_field( 'event_date', $post->ID );
$repeater = get_field( 'event_schedules', $post->ID );
$x = 0;
foreach ($repeater as $item) {
unset($item['schedule_info']);
$schedules = array ('location'=>$item['location'],'location_new'=>$item['location_new'],'event_date'=>$item['event_date'],'start_time'=>$item['start_time'],'end_time'=>$item['end_time'], 'all_day'=>$item['all_day'], 'cancel'=>$item['cancel'], 'is_location_change'=>$item['is_location_change']);
$attributes['event_schedules'][$x] = $schedules;
$x = $x + 1;
}
return $attributes;
}
阿尔及利亚仪表板
【问题讨论】: