要将文章索引推送到Algolia的wp_searchable_posts索引,但不推送到其他索引,您可以使用以下代码示例:
// 设置文章索引推送到Algolia的wp_searchable_posts索引
add_filter( 'algolia_post_shared_attributes', 'custom_algolia_post_shared_attributes', 10, 2 );
function custom_algolia_post_shared_attributes( $attributes, $post ) {
// 检查文章类型是否为post
if ( $post->post_type === 'post' ) {
// 将文章索引推送到wp_searchable_posts索引
$attributes['indexing_groups'] = array( 'wp_searchable_posts' );
}
return $attributes;
}
// 禁止将文章索引推送到其他索引
add_filter( 'algolia_should_index_post', 'custom_algolia_should_index_post', 10, 2 );
function custom_algolia_should_index_post( $should_index, $post ) {
// 检查文章类型是否为post
if ( $post->post_type === 'post' ) {
// 禁止将文章索引推送到其他索引
$should_index = false;
}
return $should_index;
}
将上述代码添加到您的WordPress主题的functions.php文件中。这将确保文章只被推送到Algolia的wp_searchable_posts索引,而不会被推送到其他索引。请记得保存文件并清除任何缓存以使更改生效。
这是一个基本的示例,您可以根据自己的需要进行自定义。请确保将相关的索引名称替换为您正在使用的实际索引名称。