• Resolved Rvervuurt

    (@rvervuurt)


    Hello!

    Recently, my client’s integration started to index post types which I have excluded with algolia_excluded_post_types.

    This is my snippet, which should exclude quite some things:

    function mb_blacklist_custom_post_type( array $blacklist ) {
        $blacklist[] = 'employee';
        $blacklist[] = 'book_review';
        $blacklist[] = 'wp_template_part';
        $blacklist[] = 'acf-field';
        $blacklist[] = 'post';
        $blacklist[] = 'wp_navigation';
        $blacklist[] = 'wp_global_styles';
        $blacklist[] = 'acf-field-group';
        $blacklist[] = 'wp_template';
        $blacklist[] = 'user_request';
        $blacklist[] = 'oembed_cache';
        $blacklist[] = 'customize_changeset';
        $blacklist[] = 'custom_css';
        $blacklist[] = 'attachment';
        $blacklist[] = 'page';
        $blacklist[] = 'wp_block';
        $blacklist[] = 'users';
    
        return $blacklist;
    }
    
    add_filter( 'algolia_excluded_post_types', 'mb_blacklist_custom_post_type' );

    I tried outputting the $excluded-variable from class-algolia-settings.php, which outputs the following:

    [19-Dec-2023 09:01:12 UTC] Excluded:
    [19-Dec-2023 09:01:12 UTC] Array
    (
        [0] => nav_menu_item
        [1] => employee
        [2] => book_review
        [3] => wp_template_part
        [4] => acf-field
        [5] => post
        [6] => wp_navigation
        [7] => wp_global_styles
        [8] => acf-field-group
        [9] => wp_template
        [10] => user_request
        [11] => oembed_cache
        [12] => customize_changeset
        [13] => custom_css
        [14] => attachment
        [15] => page
        [16] => wp_block
        [17] => users
        [18] => revision
        [19] => custom_css
        [20] => customize_changeset
        [21] => oembed_cache
        [22] => user_request
        [23] => wp_block
        [24] => wp_global_styles
        [25] => wp_navigation
        [26] => wp_template
        [27] => wp_template_part
        [28] => kr_request_token
        [29] => kr_access_token
        [30] => deprecated_log
        [31] => async-scan-result
        [32] => scanresult
    )

    This is before array_unique(), but as you can see, attachment (14) and page (15) are in the list.

    However, whenever the index is running, it’s indexing all media files and all pages. It’s not indexing employee, because that post type has 'exclude_from_search' => true,.

    What could be the reason the algolia_excluded_post_types-function suddenly stopped working?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Where are you seeing the post types in question showing up at? In Autocomplete? or in instantsearch?

    I’m looking at line 296 of wp-content/plugins/wp-search-with-algolia/includes/class-algolia-plugin.php which is the only place that’s using the get_excluded_post_types() method where that filter is being applied, and I believe it’s more for the Autocomplete indices. Though I believe we need to work on our documentation for that fact.

    If you’re working more with Instantsearch, which is sounds like, you’d want to make use of this filter:

    $searchable_post_types = (array) apply_filters( 'algolia_searchable_post_types', $searchable_post_types );
    $this->indices[] = new Algolia_Searchable_Posts_Index( $searchable_post_types );

    It’s going to be a bit more about removing post types from the passed array, instead of adding to the list. So you’d want to make use of PHP’s unset() and whatnot.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    @rvervuurt did my notes above help get things working like expected again?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Excluded post types not working anymore’ is closed to new replies.