Ver código fonte

:sparkles: wp_query for materials

tags/0.9.0
J 4 anos atrás
pai
commit
f3c02f5043
1 arquivos alterados com 22 adições e 9 exclusões
  1. 22
    9
      plugins/cia-endpoints/includes/class.make-sortby.php

+ 22
- 9
plugins/cia-endpoints/includes/class.make-sortby.php Ver arquivo

@@ -33,6 +33,23 @@ class Make_Sort_By extends WP_REST_Controller {
33 33
             $args['orderby'] = 'ends';
34 34
         }
35 35
         
36
+        if($this->post_type == 'artist') {
37
+            $tax_id_array = explode( ',', $params['materials'] );
38
+            // 3 clay
39
+            // 4 fiber
40
+            // 5 glass
41
+            // 6 metals
42
+            // 7 paper
43
+            // 8 wood
44
+            $args['tax_query'] = array(
45
+                [
46
+                    'taxonomy' => 'material',
47
+                    'field'    => 'term_id',
48
+                    'terms'    => $tax_id_array
49
+                ]
50
+            );
51
+        }
52
+        
36 53
         return $args;
37 54
     }
38 55
     /**
@@ -82,17 +99,13 @@ class Make_Sort_By extends WP_REST_Controller {
82 99
     }
83 100
 
84 101
     public function by_material( $request ) {
85
-        global $wpdb;
86
-        // !: Make this a real query
87
-        $res = $wpdb->get_results($wpdb->prepare(
88
-            "SELECT * FROM wp_posts
89
-            WHERE post_type = %s
90
-            AND post_status = 'publish'",
91
-            $this->post_type
92
-        ));
102
+        $q = new WP_Query($this->make_args($request, null));
103
+        // $args['max'] $q->max_num_pages;
104
+        $found_posts = $q->get_posts();
93 105
         wp_reset_postdata();
94 106
 
95
-        return new WP_REST_Response( $this->prepare_items_for_reponse($res), 200 );
107
+        return new WP_REST_Response( $this->prepare_items_for_reponse($found_posts), 200 );
108
+
96 109
     }
97 110
     
98 111
     public function by_past( $request ) {

Carregando…
Cancelar
Salvar