• Hello,

    on our website the search suggestions works well. But if you click search button to go to the search results page, it shows only 1 result.

    Also, if we enable search page setting “Use Algolia with Instantsearch.js“, the page shows a number of results found (counter below the search field), but no actual results – 0 posts.

    Are you aware what the problem can be?

    Thank you!

    The page I need help with: [log in to see the link]

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

    (@tw2113)

    The BenchPresser

    Which search version do you have configured presently? I’m not seeing hints of Instantsearch so I’m suspecting it’s the “Use with Native Search Template.”

    Have you checked and verified that the wp_searchable_posts index in your Algolia dashboard has records in it?

    Thread Starter Themico

    (@themico)

    Thank you for your response.

    Yes, I have 273 records in wp_searchable_posts in Algolia.

    Can the problem be caused by the code snippet that I use. I only want to index specific pages and exclude everything else. Sorry, I forgot to notice it in my initial post.


    function my_exclude_custom_post_type( array $exclude ) {
    $exclude[] = 'post';

    return $exclude;
    }
    add_filter( 'algolia_excluded_post_types', 'my_exclude_custom_post_type' );

    function algolia_exclude_extra( $should_index, $post ) {
    // Check if the post type is 'page'
    if ( in_array( $post->post_type, [ 'page' ] ) ) {
    // Check if the post belongs to the 'Services' category
    if ( ! has_category( 7, $post ) ) {
    // Exclude the post from being indexed
    return false;
    }
    } else {
    return false;
    }

    // Allow indexing for all other cases
    return $should_index;
    }

    add_filter( 'algolia_should_index_searchable_post', 'algolia_exclude_extra', 10, 2 );
    add_filter( 'algolia_should_index_post', 'algolia_exclude_extra', 10, 2 );
    Thread Starter Themico

    (@themico)

    I disabled the snippet, but it is still same.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    So, yes, you are making use of algolia_excluded_post_types filter, but one thing I think we need to do with better clarifying is that filter is specifically for the autocomplete page and those settings.

    If you check out https://github.com/WebDevStudios/wp-search-with-algolia/wiki/Filter-Hooks there’s a section for the Search page settings/Instantsearch, for which I’ve pasted the intended filter example below.

    <?php
    function my_exclude_searchable_custom_post_type( array $post_types ) {
    if ( array_key_exists( 'custom_post_type', $post_types ) ) {
    unset( $post_types['custom_post_type'] );
    }

    return $post_types;
    }
    add_filter( 'algolia_searchable_post_types', 'my_exclude_searchable_custom_post_type' );

    As per one of the notes there:

    With this hook, we’ve already fetched all the post types that have exclude_from_search set to false, so we need to remove instead of add.

    You’ll want to update the custom_post_type part to match which you want to exclude, and repeat as necessary. Alternatively if you know exactly which post type you want, you could have the filter return something like this, for example just have it index the page post type.

    return [ 'page' => 'page' ];

    Regarding the indexing/not indexing part your exclusion function may be best done as such

    function algolia_exclude_extra( $should_index, $post ) {
    // Check if the post type is 'page'
    if ( in_array( $post->post_type, [ 'page' ] ) ) {
    // Check if the post belongs to the 'Services' category
    if ( ! has_category( 7, $post ) ) {
    // Exclude the post from being indexed
    return false;
    }
    }

    // Allow indexing for all other cases
    return $should_index;
    }
    add_filter( 'algolia_should_index_searchable_post', 'algolia_exclude_extra', 10, 2 );
    add_filter( 'algolia_should_index_post', 'algolia_exclude_extra', 10, 2 );

    From your original version, it looks like the return $should_index line was never getting reached, because your else clause also returned false.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.