• Resolved HJ

    (@coach-henk)


    Hi there,

    I excluded a category on the main shop page with the function as explained on WC:

    /**
     * Exclude products from a particular category on the shop page
     */
    function custom_pre_get_posts_query( $q ) {
    
        $tax_query = (array) $q->get( 'tax_query' );
    
        $tax_query[] = array(
               'taxonomy' => 'product_cat',
               'field' => 'slug',
               'terms' => array( 'soldproducts' ), // Don't display sold products on the shop page.
               'operator' => 'NOT IN'
        );
    
        $q->set( 'tax_query', $tax_query );
    
    }
    add_action( 'woocommerce_product_query', 'custom_pre_get_posts_query' );

    So far so good, but as of this the products in this category don’t also show up in a search in WC.

    Is there a way to:
    1. show the products in this category “soldproducts” in the WC search results, or
    2. make a seperate search function for the “soldproducts”?

    Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Exclude category shop page, but show in search results’ is closed to new replies.