• Resolved nickmohler

    (@nickmohler)


    I’ve been trying to figure out how to exclude a page based on its ID (or other attribute) from search results and while I can delete it from the index, if I make any updates to the page, it appears again. I have the page marked for noindex nofollow for Google.

    I’ve attempted to understand how to create a filter to remove it from the index but I’m not clear where I need to place the code referenced related to Filter Hooks (here: https://github.com/WebDevStudios/wp-search-with-algolia/wiki/Filter-Hooks).

    Any assistance is appreciated. This page must not appear in the Algolia search results on our site and I’m at a loss for how to easily remove it without a skilled web developer. Thanks!

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

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

    (@tw2113)

    The BenchPresser

    Hi @nickmohler

    Feeling like this page isn’t obvious at the moment, but I’d check out https://github.com/WebDevStudios/wp-search-with-algolia/wiki/Automated-Sync

    Towards the bottom there’s a heading of “Exclude a post by it’s ID” however I’m also posting the code here directly for easy access and identification.

    <?php
    /**
     * @param bool    $should_index
     * @param WP_Post $post
     *
     * @return bool
     */
    function filter_post( $should_index, WP_Post $post )
    {
        if ( 18517 === $post->ID ) {
            return false;
        }
    
        return $should_index;
    }
    
    // Hook into Algolia to manipulate the post that should be indexed.
    add_filter( 'algolia_should_index_searchable_post', 'filter_post', 10, 2 );
    add_filter( 'algolia_should_index_post', 'filter_post', 10, 2 );

    This would cover both the InstantSearch and the Autocomplete indexes. This can be pasted into your active theme’s functions.php file and next time you update the page or do a bulk index, this code should prevent it from getting included in the indexes.

Viewing 1 replies (of 1 total)

The topic ‘Exclude page from index’ is closed to new replies.