【问题标题】:Algolia - Wordpress - exclude certain pages from indexAlgolia - Wordpress - 从索引中排除某些页面
【发布时间】:2025-11-21 15:25:04
【问题描述】:

目前我正在索引 Algolia 的所有 wordpress 页面。

在 Algolia 将某些页面排除在索引之外的最佳方法是什么?应该有大约 20 页需要排除。

【问题讨论】:

    标签: wordpress algolia


    【解决方案1】:

    您可以执行以下操作以按 ID 排除某些帖子:

    /**
     * @param bool    $flag
     * @param WP_Post $post
     *
     * @return bool
     */
    function custom_should_index_post( $flag, WP_Post $post ) {
    
        // TODO: Replace with your own post IDs to exclude. 
        $excluded_ids = array( 20, 25 );
        if ( in_array( $post->ID, $excluded_ids ) ) {
            return false;
        }
    
        return $flag;
    }
    
    add_filter( 'algolia_should_index_post', 'custom_should_index_post', 10, 2 );
    add_filter( 'algolia_should_index_searchable_post', 'custom_should_index_post', 10, 2 );
    

    当然,您也可以根据任何其他值(例如帖子类型或自定义属性)做出决定。

    【讨论】:

      最近更新 更多