Advertisement
wpgenie

search only active / running auctions

Nov 19th, 2015
490
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.67 KB | None | 0 0
  1. add_filter('woocommerce_product_query','custom_pre_get_posts' ,99,2 );
  2.  
  3. function custom_pre_get_posts($q){
  4.     if ( ! is_admin() && $q->is_main_query() && $q->is_search() && isset ( $q->query['only_active_auctions']) ){
  5.  
  6.         $metaquery = $q->get('meta_query');
  7.         $metaquery []=
  8.                     array(
  9.                        
  10.                         'key' => '_auction_started',
  11.                         'compare'=> 'NOT EXISTS',
  12.                                    
  13.                         );
  14.         $metaquery []=
  15.                     array(
  16.                        
  17.                         'key' => '_auction_closed',
  18.                         'compare'=> 'NOT EXISTS'                       
  19.                         );         
  20.         $q->set( 'meta_query', $metaquery );
  21.  
  22.         return;
  23.     }
  24.     return;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement