Documentation - Actions / Filters - Filter – apto/interface_query_args

Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInPrint this page

Filter – apto/interface_query_args

The filter allow to change arguments for the query which output the objects in a sort list. The filter send through 2 argument:

  • $args
  • $current_sort_view_ID

The following code exclude all hidden WooCommerce products which are set to  Visibility Hidden, for a sort id 114:


	add_filter('apto/interface_query_args', 'apto_interface_query_args', 99, 2);
    function  apto_interface_query_args($args, $current_sort_view_ID)
        {
            
            if ( $args['sort_id']   !=  114)
                return $args;
         
            $additional_query   =   array(
                                            'taxonomy' =>   'product_visibility',
                                            'field'    =>   'slug',
                                            'terms'    =>   array('exclude-from-search', 'exclude-from-catalog'),
                                            'operator' =>   'NOT IN',
                                );
   
            if  ( isset($args['tax_query']) )
                $args['tax_query'][]    =   $additional_query;
                else
                $args['tax_query']  =   array ( $additional_query ) ;
                
            return $args;  
        }