• Resolved creativewebdesigns03

    (@creativewebdesigns03)


    I have taken various steps to prevent certain products and categories from being seen.

    I have edited the functions.php to exclude certain categories. THat works.

    I have also submitted certain categories to be hidden using Google Search Console. The categories are hidden.
    https://wegodown.ca/product-category/parts/ show no results. This is good.

    However, the products within those categories still are showing up in search results.
    I have even set the particular products to ‘visibility -> hidden’

    As an example: all ‘parts’ products should not be viewable, but if I search, it shows up. https://wegodown.ca/?s=EO+cord+Adapter+and+Battery

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • Saif

    (@babylon1999)

    Hello @creativewebdesigns03!

    This is a known bug. Since products are custom post types, the global search feature of WordPress will still detect them. I’m not certain how you can accomplish this with your theme, but adding the following parameter should resolve the issue: ?post_type=product

    Cheers!

    Hi @creativewebdesigns03,

    You should append &post_type=product to the search URL. For example, example.com/?s=dogs&post_type=product will restrict the search results to products.

    To make this work, you can use the following filter:

    function filter_product_search( $query ) {
        if ( $query->is_search() && !is_admin() ) {
            // Ensure the search includes only products
            $query->set( 'post_type', 'product' );
        }
    }
    add_action( 'pre_get_posts', 'filter_product_search' );
    

    Add this code to your functions.php file, and it will resolve the issue. This will ensure that every search on your site includes &post_type=product, limiting the results to products only.

    So, when you search for something like “EO cord Adapter and Battery”, the search URL will be:
    https://wegodown.ca/?s=EO+cord+Adapter+and+Battery&post_type=product

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

The topic ‘Products hidden are still being displayed’ is closed to new replies.