br_aapf_args_parser

Br_aapf_args_parser - extend $args based on passed filters.

Description

(array) br_aapf_args_parser( (array) $args = array() ); 

Returns (array)

Parameters (1)

0. $args — Optional. (array) => array()
The args.

Usage

  1. if ( !function_exists( 'br_aapf_args_parser' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'advanced-ajax-product-filters-for-woocommerce/includes/functions.php'; 
  3.  
  4. // The args. 
  5. $args = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = br_aapf_args_parser($args); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/functions.php  
  1. function br_aapf_args_parser( $args = array() ) { 
  2. $attributes_terms = $tax_query = array(); 
  3. $taxonomies = array(); 
  4.  
  5. if ( @$attributes ) { 
  6. foreach ( $attributes as $k => $v ) { 
  7. $terms = get_terms( array( $k ), $args = array( 'orderby' => 'name', 'order' => 'ASC', 'fields' => 'id=>slug' ) ); 
  8. if ( $terms ) { 
  9. foreach ( $terms as $term_id => $term_slug ) { 
  10. $attributes_terms[ $k ][ $term_id ] = $term_slug; 
  11. unset( $terms ); 
  12. unset( $attributes ); 
  13.  
  14. if ( @$_POST['terms'] ) { 
  15. foreach ( $_POST['terms'] as $t ) { 
  16. if( !isset($taxonomies[ $t[0] ]) ) { 
  17. $taxonomies[ $t[0] ] = array(); 
  18. $taxonomies[ $t[0] ][] = @ $attributes_terms[ $t[0] ][ $t[1] ]; 
  19. $taxonomies_operator[ $t[0] ] = $t[2]; 
  20. unset( $attributes_terms ); 
  21.  
  22. $taxonomies = apply_filters( 'berocket_aapf_listener_taxonomies', @$taxonomies ); 
  23. $taxonomies_operator = apply_filters( 'berocket_aapf_listener_taxonomies_operator', @$taxonomies_operator ); 
  24.  
  25. if ( @$taxonomies ) { 
  26. $tax_query['relation'] = 'AND'; 
  27. if ( $taxonomies ) { 
  28. foreach ( $taxonomies as $k => $v ) { 
  29. if ( $taxonomies_operator[ $k ] == 'AND' ) { 
  30. $op = 'AND'; 
  31. } else { 
  32. $op = 'IN'; 
  33.  
  34. $tax_query[] = array( 
  35. 'taxonomy' => $k,  
  36. 'field' => 'slug',  
  37. 'terms' => $v,  
  38. 'operator' => $op 
  39. ); 
  40.  
  41. if ( @$_POST['product_cat'] and $_POST['product_cat'] != '-1' ) { 
  42. $tax_query[] = array( 
  43. 'taxonomy' => 'product_cat',  
  44. 'field' => 'slug',  
  45. 'terms' => strip_tags( $_POST['product_cat'] ),  
  46. 'operator' => 'IN' 
  47. ); 
  48.  
  49. $args['tax_query'] = $tax_query; 
  50. $args['post_type'] = 'product'; 
  51.  
  52. if ( @ $_POST['orderby'] ) { 
  53.  
  54. return $args;