|
|
@@ -34,31 +34,16 @@ class Make_Sort_By extends WP_REST_Controller {
|
|
34
|
34
|
$args['orderby'] = 'ends';
|
|
35
|
35
|
}
|
|
36
|
36
|
|
|
37
|
|
- if($this->post_type == 'artist') {
|
|
38
|
|
- // Default to all materials
|
|
39
|
|
- $tax_id_array = [2, 3, 4, 5, 6, 7, 8];
|
|
40
|
|
-
|
|
41
|
|
- if ($params['materials']) {
|
|
42
|
|
- $tax_id_array = explode( ',', $params['materials'] );
|
|
43
|
|
- }
|
|
44
|
|
- // 2 clay
|
|
45
|
|
- // 3 fiber
|
|
46
|
|
- // 4 glass
|
|
47
|
|
- // 5 metals
|
|
48
|
|
- // 6 other
|
|
49
|
|
- // 7 paper
|
|
50
|
|
- // 8 wood
|
|
51
|
|
- $args['tax_query'] = array(
|
|
52
|
|
- [
|
|
53
|
|
- 'taxonomy' => 'material',
|
|
54
|
|
- 'field' => 'term_id',
|
|
55
|
|
- 'terms' => $tax_id_array
|
|
56
|
|
- ]
|
|
57
|
|
- );
|
|
58
|
|
- }
|
|
59
|
|
-
|
|
60
|
37
|
return $args;
|
|
61
|
38
|
}
|
|
|
39
|
+ function make_terms_array($taxonomy, $field) {
|
|
|
40
|
+ $terms = get_terms([
|
|
|
41
|
+ 'taxonomy' => $taxonomy,
|
|
|
42
|
+ 'hide_empty' => true,
|
|
|
43
|
+ 'fields' => $field
|
|
|
44
|
+ ]);
|
|
|
45
|
+ return $terms;
|
|
|
46
|
+ }
|
|
62
|
47
|
/**
|
|
63
|
48
|
* Register the routes for the objects of the controller.
|
|
64
|
49
|
*/
|
|
|
@@ -105,9 +90,51 @@ class Make_Sort_By extends WP_REST_Controller {
|
|
105
|
90
|
return new WP_REST_Response( $this->prepare_items_for_reponse($page, false), 200 );
|
|
106
|
91
|
}
|
|
107
|
92
|
|
|
|
93
|
+ public function by_type( $request ) {
|
|
|
94
|
+ $args = $this->make_args($request, null);
|
|
|
95
|
+ $params = $request->get_params();
|
|
|
96
|
+
|
|
|
97
|
+ // Get all term ID's in a given taxonomy
|
|
|
98
|
+ $taxonomy = $this->post_type . '_type';
|
|
|
99
|
+ if($this->post_type == 'post') $taxonomy = 'category';
|
|
|
100
|
+
|
|
|
101
|
+ $tax_id_array = $this->make_terms_array($taxonomy, 'ids');
|
|
|
102
|
+ $args['tax_query'] = array([
|
|
|
103
|
+ 'taxonomy' => $taxonomy,
|
|
|
104
|
+ 'field' => 'term_id',
|
|
|
105
|
+ 'terms' => $tax_id_array,
|
|
|
106
|
+ ]);
|
|
|
107
|
+
|
|
|
108
|
+ $q = new WP_Query($args);
|
|
|
109
|
+ $found_posts = $q->get_posts();
|
|
|
110
|
+ wp_reset_postdata();
|
|
|
111
|
+
|
|
|
112
|
+ return new WP_REST_Response( $this->prepare_items_for_reponse($found_posts), 200 );
|
|
|
113
|
+ }
|
|
|
114
|
+
|
|
108
|
115
|
public function by_material( $request ) {
|
|
109
|
|
- $q = new WP_Query($this->make_args($request, null));
|
|
110
|
|
- // $args['max'] $q->max_num_pages;
|
|
|
116
|
+ $args = $this->make_args($request, null);
|
|
|
117
|
+ $params = $request->get_params();
|
|
|
118
|
+
|
|
|
119
|
+ // Default to all materials
|
|
|
120
|
+ $taxonomy = 'material';
|
|
|
121
|
+ $tax_id_array = $this->make_terms_array($taxonomy, 'ids');
|
|
|
122
|
+
|
|
|
123
|
+ // Filter with a materials array
|
|
|
124
|
+ // 2: clay
|
|
|
125
|
+ // 3: fiber
|
|
|
126
|
+ // 4: glass
|
|
|
127
|
+ // 5: metals
|
|
|
128
|
+ // 6: other
|
|
|
129
|
+ // 7: paper
|
|
|
130
|
+ // 8: wood
|
|
|
131
|
+ if ($params['materials']) $tax_id_array = explode( ',', $params['materials'] );
|
|
|
132
|
+ $args['tax_query'] = array([
|
|
|
133
|
+ 'taxonomy' => $taxonomy,
|
|
|
134
|
+ 'field' => 'term_id',
|
|
|
135
|
+ 'terms' => $tax_id_array
|
|
|
136
|
+ ]);
|
|
|
137
|
+ $q = new WP_Query($args);
|
|
111
|
138
|
$found_posts = $q->get_posts();
|
|
112
|
139
|
wp_reset_postdata();
|
|
113
|
140
|
|
|
|
@@ -116,19 +143,15 @@ class Make_Sort_By extends WP_REST_Controller {
|
|
116
|
143
|
|
|
117
|
144
|
public function by_past( $request ) {
|
|
118
|
145
|
$q = new WP_Query($this->make_args($request, '<='));
|
|
119
|
|
- // $args['max'] $q->max_num_pages;
|
|
120
|
146
|
$found_posts = $q->get_posts();
|
|
121
|
147
|
wp_reset_postdata();
|
|
122
|
|
-
|
|
123
|
148
|
return new WP_REST_Response( $this->prepare_items_for_reponse($found_posts), 200 );
|
|
124
|
149
|
}
|
|
125
|
150
|
|
|
126
|
151
|
public function by_current_and_upcoming( $request ) {
|
|
127
|
152
|
$q = new WP_Query($this->make_args($request, '>='));
|
|
128
|
|
- // $args['max'] $q->max_num_pages;
|
|
129
|
153
|
$found_posts = $q->get_posts();
|
|
130
|
154
|
wp_reset_postdata();
|
|
131
|
|
-
|
|
132
|
155
|
return new WP_REST_Response( $this->prepare_items_for_reponse($found_posts), 200 );
|
|
133
|
156
|
}
|
|
134
|
157
|
|