wpgenie icon

search only active / running auctions

wpgenie | PRO | 11/19/15 07:59:51 PM UTC | 0 ⭐ | 1014 👁️ | Never ⏰ | []
PHP |

670 B

|

None

|

0 👍

/

0 👎

add_filter('woocommerce_product_query','custom_pre_get_posts' ,99,2 );
 
function custom_pre_get_posts($q){
    if ( ! is_admin() && $q->is_main_query() && $q->is_search() && isset ( $q->query['only_active_auctions']) ){
 
        $metaquery = $q->get('meta_query');
        $metaquery []= 
                    array(
                        
                        'key' => '_auction_started',
                        'compare'=> 'NOT EXISTS',
                                    
                        );
        $metaquery []= 
                    array(
                        
                        'key' => '_auction_closed',
                        'compare'=> 'NOT EXISTS'                        
                        );          
        $q->set( 'meta_query', $metaquery );
 
        return;
    }
    return;
}

Comments