Viewing 13 replies - 1 through 13 (of 13 total)
  • Thread Starter chillmen

    (@chillmen)

    I tried to use this code in functions.ph file, but it does not work, products are still showing in results page:

    // create search filter
    function xmit_search_filter($query) {
        if ( !$query->is_admin && $query->is_search) {
           $query->set('cat','-432,-434');
    }
    return $query;
    }
    add_filter( 'pre_get_posts', 'xmit_search_filter' );

    Someone any idea?

    Thread Starter chillmen

    (@chillmen)

    I found a solution, exclude custom post types from wp default search results, for woocommerce custom post type is “product” and i don’t need to make the products hidden.
    You can use it to exclude any custom post type from wp search results page.

    /** Exclude woocommerce products from wp default search results */
    add_action( 'init', 'update_my_custom_type', 99 );
    function update_my_custom_type() {
        global $wp_post_types;
    
        if ( post_type_exists( 'product' ) ) {
    
            // exclude from search results
            $wp_post_types['product']->exclude_from_search = true;
        }
    }

    I found the code here

    Hello, chillmen!
    thanks for sharing this code, but when i use it, i have some trouble:
    don’t showing products in product category page.
    i have no idea why?maybe your have some thoughts about it?
    Thanks.

    subscribe

    same by me, works fine, but doesn’t show any woocommerce-category results any more… any solutions?
    thanks!

    I have this same issue: When using the code above, the products no longer display in WooCommerce categories.

    Since the regular categories still work, this must be something within the WooCommerce plugin?

    Anyone have any ideas? If you don’t have time to post coding, where would I begin to troubleshoot? (Beginner coder level)

    ~ thanks

    Guys,
    I had the same problems as above.
    Fixed everything by installing the ‘Search Exclude’ (Roman Pronskiy) plugin.
    Allows you to hide any page from search (post, pages, portfolio pages, products, etc). Also works in combination with Relevanssi.

    Sounds great… but I would have to exclude each product-item seperately, right? Would be a lot of work… and although it will show the items of the productcategories?

    thanks

    This will suffice for my composite products on woocommerce…thanks alpexis..! Been looking for something like this for a while ??

    hi

    I’m still searching for the perfect solution here. ‘Search Exclude’ is great, but I can’t search for the excluded products at the shop page / productsearch as well (logically). Which would be important.

    Has someone an other idea? Like the code from the beginning but with Productcategory funtionality? ??

    thanks!!

    hey, got some help from ‘search exclude’! pretty amazing plugin which solved the whole problem.

    https://www.ads-software.com/support/topic/exclude-products-for-regular-search-but-not-woocommerce-search?replies=4#post-7179865

    Hi,ndesign55
    i want to show the main product of woocommerce an hide or exclude the composite product.
    i think you got some inputs from Search Exclude can you please let me know how you did that
    TY

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘How to remove woocommerce hidden products from wordpress default search results?’ is closed to new replies.