Back to Community

Why Hidden and Private WooCommerce Products Still Appear in Search Results (And How to Fix It)

12 threads Sep 7, 2025 PluginWoocommerce

Content

If you've ever set a WooCommerce product to Hidden or Private only to find it still appears in your site's search results, you're not alone. This is a common and frustrating issue that can lead to customers finding products you intended to keep out of the public eye. This guide explains why this happens and provides the most effective solutions.

Understanding the Problem: Hidden vs. Private vs. Search

First, it's important to understand what the different visibility settings are supposed to do:

  • Hidden: Products marked as "Hidden" should not appear on shop pages, category pages, or in WooCommerce-specific search results. However, they remain accessible via their direct URL.
  • Private: A standard WordPress "Private" post status should hide the product from everyone except logged-in administrators. It should not appear anywhere on the front end.

The core of the issue is that these settings primarily affect WooCommerce's own product queries. Your site's default WordPress search (?s=product) often uses a different, broader query that does not respect these visibility settings by default. This is a known, long-standing issue in the WooCommerce ecosystem.

Common Solutions and Workarounds

Since this behavior is not fully handled by WooCommerce core, implementing a fix requires adding custom code to your site. Here are the most common and effective methods.

Solution 1: Code to Exclude Hidden Products from WordPress Search

The following code snippet modifies the main WordPress search query to exclude products with "Hidden" catalog visibility. You can add this code to your child theme's functions.php file or use a code snippets plugin.

function exclude_hidden_products_from_search( $query ) {
    if ( ! is_admin() && $query->is_search() && $query->is_main_query() ) {
        $meta_query = $query->get( 'meta_query' );
        if ( empty( $meta_query ) ) {
            $meta_query = array();
        }
        // Exclude products hidden from catalog
        $meta_query[] = array(
            'key'     => '_visibility',
            'value'   => 'hidden',
            'compare' => '!='
        );
        $query->set( 'meta_query', $meta_query );
    }
}
add_action( 'pre_get_posts', 'exclude_hidden_products_from_search' );

Solution 2: Code to Exclude Private Products from All Front-End Queries

To ensure products with a "Private" status never appear in any front-end search or listing, use this code. This is a more comprehensive approach for highly sensitive products.

function exclude_private_products( $query ) {
    if ( ! is_admin() && $query->is_main_query() ) {
        // Check if it's a search or any other front-end product query
        if ( $query->is_search() || ( isset( $query->query_vars['post_type'] ) && $query->query_vars['post_type'] === 'product' ) ) {
            $post_status = $query->get( 'post_status' );
            // If post_status is not explicitly set, set it to only public statuses
            if ( empty( $post_status ) ) {
                $query->set( 'post_status', 'publish' );
            }
        }
    }
}
add_action( 'pre_get_posts', 'exclude_private_products' );

Important Considerations Before Proceeding

  • Backup Your Site: Always create a full backup of your website before adding custom code.
  • Use a Child Theme: Adding code directly to your theme's functions.php file is not recommended, as updates will erase your changes. Use a child theme or a management plugin.
  • Test Thoroughly: After implementing any code, test your site's search functionality extensively to ensure it works as expected and doesn't break other features.
  • Plugin Conflicts: If the problem persists after adding the code, a conflict with another plugin or your theme might be overriding the query. Try disabling other plugins temporarily to test.

While the WooCommerce team is aware of this discrepancy between product visibility and search behavior, a core fix has not yet been implemented. The custom code provided above serves as a reliable and widely-used workaround for store owners needing to control their product visibility completely.