-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWEFQuery.php
60 lines (45 loc) · 1.19 KB
/
WEFQuery.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/**
* WEFQuery
*/
class WEFQuery
{
public static function query($query)
{
$url_parts = parse_url( wef_current_uri() );
parse_str($url_parts['query'], $params);
$prod_attr = array();
foreach ($params as $key => $value) {
$realKey = 'pa_'.$key;
$prod_attr[] = [
'taxonomy' => $realKey,
'terms' => $value,
];
/* if (substr($key, 0 , 3)=='pa_'){
$prod_attr[] = [
'taxonomy' => $key,
'terms' => $value,
];
}*/
}
// print_r( $prod_attr);
// die();
$taxquery = array('relation' => 'AND');
foreach ($prod_attr as $key => $value) {
$terms = explode(",", $value['terms']);
// if ( count($terms) == 0)
// $terms = $value['terms'];
$taxquery [] = array(
'taxonomy' => $value['taxonomy'],
'field'=> 'slug',
'terms' => $terms,
'include_children' => false,
// 'operator'=> 'IN',
);
}
if( $query->is_main_query() and !$query->is_search){
$query->set( 'tax_query', $taxquery );
return $query;
}
}
}