Преглед на файлове

:sparkles: wp_query for materials

tags/0.9.0
J преди 4 години
родител
ревизия
f3c02f5043
променени са 1 файла, в които са добавени 22 реда и са изтрити 9 реда
  1. 22
    9
      plugins/cia-endpoints/includes/class.make-sortby.php

+ 22
- 9
plugins/cia-endpoints/includes/class.make-sortby.php Целия файл

33
             $args['orderby'] = 'ends';
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
         return $args;
53
         return $args;
37
     }
54
     }
38
     /**
55
     /**
82
     }
99
     }
83
 
100
 
84
     public function by_material( $request ) {
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
         wp_reset_postdata();
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
     public function by_past( $request ) {
111
     public function by_past( $request ) {

Loading…
Отказ
Запис