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

TIPS

May 22, 2019 | WooCommerce Tips | 0 comments

Add the function below to your child theme functions.php file. [php] /* 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’ ); [/php]

0 Comments

Submit a Comment

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

More Tips

Ad - Web Hosting from SiteGround - Crafted for easy site management. Click to learn more.

Cloudways Hosting

WPEngine Hosting

Pressable Hosting

AccuWeb Hosting

Ask the Divi Guy a Question

"*" indicates required fields