Forum Replies Created

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter alexryans

    (@alexryans)

    Hi @tw2113, thanks for getting back to me so quickly!

    I can confirm that your first suggestion worked perfectly – amazed it was such a simple, one-line fix, that’s saved me a massive potential headache.

    Thanks for your help, happy to close this one off now.

    Thread Starter alexryans

    (@alexryans)

    For further context, we have a global, all-results Algolia search (autocomplete) in our site’s header, which sits across all pages.

    We have a secondary Algolia autocomplete which sits inside the Collections archive page, which only brings results back from the collections post type – this is all working exactly as intended.

    My question, however, relates to the standard WordPress search results page which appears when hitting ENTER inside the search input field (essentially site.co.uk/?s=SEARCH_QUERY). It is this page that I only want to show results from the collections post type when someone hits ENTER on the secondary Collections-only search input field and, when they search via the standard search input in the header, the normal operation of showing hits from all results should be displayed.

    Thread Starter alexryans

    (@alexryans)

    For completion purposes, here’s the final code I used to achieve this:

    
    // We alter the indexing decision making for both the posts index and the searchable_posts index.
    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);
    
    /**
     * @param bool    $should_index
     * @param WP_Post $post
     *
     * @return bool
     */
    function custom_should_index_post($should_index, WP_Post $post) {
        if (false === $should_index) {
            // If the decision has already been taken to not index the post
            // stick to that decision.
            return $should_index;
        }
    
        if ($post->post_type !== 'page') {
            // We only want to alter the decision making for pages.
            // We we are dealing with another post_type, return the $should_index as is.
            return  $should_index;
        }
    
        $woocommerce_page_ids = [
            get_option('woocommerce_cart_page_id'),
            get_option('woocommerce_checkout_page_id'),
            get_option('woocommerce_myaccount_page_id')
        ];
    
        if (in_array($post->ID, $woocommerce_page_ids)) {
            // If the post is a page and has an excluded page ID,
            // we return false to inform that we do not want to index the post.
            return false;
        }
    
        return $should_index;
    }
    
    • This reply was modified 4 years, 12 months ago by alexryans.
    • This reply was modified 4 years, 12 months ago by alexryans.
    Thread Starter alexryans

    (@alexryans)

    Hi Michael,

    That’s great, thank you – I’ll take a look at that article and get back in touch with any further questions.

    Thread Starter alexryans

    (@alexryans)

    OK, great, thanks, that makes sense! How would I go about deleting certain pages from the posts_page index?

    Thread Starter alexryans

    (@alexryans)

    Thanks for getting back to me, Bradford – the link to one of the article in question is http://blog.screeningapp.co.uk/article/batmans-back-first-trailers-lego-batman-movie/ and, no, filename.jpg isn’t the real file name, it’s just a placeholder for the actual filename of the featured image.

    Just for clarity, the featured image is the large banner image at the top of the page.

    Thread Starter alexryans

    (@alexryans)

    Note that I’ve now resolved this issue by following the instructions on this thread, by including the images attached to the article inside a folder alongside the downloaded JSON.

    Due to limitations with certain web hosts, the plugin only exports the JSON file and not the associated images. It’s likely that you’re dragging the JSON into the News Preview tool without the images. If you download those from WordPress and bundle them manually (i.e. place them into a folder with the JSON file) and drag that into News Preview, it should work fine.

Viewing 7 replies - 1 through 7 (of 7 total)