Pricing Process Reviews Contact

Divi Guy blog

How to prevent hidden WooCommerce products from showing up in WordPress search results

Add the function below to your child theme functions.php file.

/* Preventing Hidden WooCommerce products from showing up in WordPress search results */ if ( ! function_exists( ‘gamma_search_query_fix’ ) ){ function gamma_search_query_fix( $query = false ) { if(!is_admin() && is_search()){ $query->set( ‘meta_query’, array( ‘relation’ => ‘OR’, array( ‘key’ => ‘_visibility’, ‘value’ => ‘hidden’, ‘compare’ => ‘NOT EXISTS’, ), array( ‘key’ => ‘_visibility’, ‘value’ => ‘hidden’, ‘compare’ => ‘!=’, ), )); } } } add_action( ‘pre_get_posts’, ‘gamma_search_query_fix’ ); 

Need a hand?

Need help with your Divi website?

Book a Divi consultation and we can fix it together over Zoom, or ask for an estimate for bigger jobs.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Search

Browse

More tips

Got a question?

Ask me anything

Stuck on something in Divi or WordPress? Ask away and I will reply by email, usually within 24 hours.

Ask a Question

Tell me about your project. The more details the better.

"*" indicates required fields

Make a payment

Got an invoice?

Pay an invoice, a deposit or a tip in about a minute. Card or PayPal, secure checkout, and I never see your card number.

Make a payment