Advertisement
meetsos

Prevent Hidden Products Show in Search Results

Jan 12th, 2017
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.64 KB | None | 0 0
  1. <?php
  2. if ( ! function_exists( 'gamma_search_query_fix' ) ){
  3.   function gamma_search_query_fix( $query = false ) {
  4.     if(!is_admin() && is_search()){
  5.       $query->set( 'meta_query', array(
  6.         'relation' => 'OR',
  7.         array(
  8.           'key' => '_visibility',
  9.           'value' => 'hidden',
  10.           'compare' => 'NOT EXISTS',
  11.         ),
  12.         array(
  13.           'key' => '_visibility',
  14.           'value' => 'hidden',
  15.           'compare' => '!=',
  16.         ),
  17.       ));
  18.     }
  19.   }
  20. }
  21. add_action( 'pre_get_posts', 'gamma_search_query_fix' );
  22. // http://www.gammafx.com/woocommerce-hidden-products-in-wordpress-search-results/
  23. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement