【发布时间】:2017-09-13 19:21:31
【问题描述】:
我试图从 CPT“事件”的“events_status”分类中排除 ID 为 3795 的单个术语“存档”。尝试重新索引 WordPress 后端中的“事件”cpt 时,出现空错误弹出窗口。这是我的代码:
// EXCLUDE TERM FROM BEING INDEXED
function custom_should_index_term( $should_index, WP_Post $post ) {
$terms_to_exclude = array( 3795 );
if ( false === $should_index ) {
return $should_index;
}
if ( $post->post_type !== 'events' ) {
return $should_index;
}
$post_term_ids = wp_get_post_terms( $post->ID, 'events_status' );
$remaining_term_ids = array_diff( $post_term_ids, $terms_to_exclude
);
if ( count( $remaining_term_ids ) === 0 ) {
return false;
}
return $should_index;
}
add_filter('algolia_should_index_post', 'custom_should_index_term',
10, 2);
add_filter('algolia_should_index_searchable_post',
'custom_should_index_term', 10, 2);
【问题讨论】: