Просмотр исходного кода

:sparkles: added orderby and order

tags/0.9.0
J 4 лет назад
Родитель
Сommit
3347fb2a2d
1 измененных файлов: 13 добавлений и 12 удалений
  1. 13
    12
      plugins/cia-endpoints/includes/class.make-endpoint.php

+ 13
- 12
plugins/cia-endpoints/includes/class.make-endpoint.php Просмотреть файл

46
         $args = array(
46
         $args = array(
47
             'post_type' => $this->post_type,
47
             'post_type' => $this->post_type,
48
             'post_status' => ['publish'],
48
             'post_status' => ['publish'],
49
-            //(int) - number of post to show per page (available with Version 2.1). Use 'posts_per_page' => -1 to show all posts. 
50
             'posts_per_page' => -1,
49
             'posts_per_page' => -1,
51
-            'page' => 1
52
-            // Order DOES NOT WORK because you're
53
-            // returning the posts by id - DUH
54
-            // 'orderby' => 'date',
55
-            // 'order' => 'DESC'
50
+            'page' => 1,
51
+            'orderby' => 'date',
52
+            'order' => 'DESC'
56
         );
53
         );
57
 
54
 
58
-        // Get parameters from request
59
-        // /<id>?limit=<num>
55
+        // Get parameters from request,
56
+        // /?limit=<num>&?orderby=<str>&?order=<str>
60
         $params = $request->get_params();
57
         $params = $request->get_params();
61
         if(intval($params['limit']) > 0) {
58
         if(intval($params['limit']) > 0) {
62
             $args['posts_per_page'] = intval($params['limit']);
59
             $args['posts_per_page'] = intval($params['limit']);
68
             $args['page'] = intval($params['p']);
65
             $args['page'] = intval($params['p']);
69
             $args['offset'] = ($args['page'] * $args['posts_per_page']) - $args['posts_per_page'];
66
             $args['offset'] = ($args['page'] * $args['posts_per_page']) - $args['posts_per_page'];
70
         }
67
         }
71
-        // !: Add order asc/desc
72
-        // !: Add orderby
68
+        if($params['orderby']) {
69
+            $args['orderby'] = $params['orderby'];
70
+        }
71
+        if($params['order']) {
72
+            $args['order'] = $params['order'];
73
+        }
73
 
74
 
74
         return new WP_REST_Response( $this->prepare_all_items_for_response($args), 200 );
75
         return new WP_REST_Response( $this->prepare_all_items_for_response($args), 200 );
75
     }
76
     }
115
         foreach( $found_posts as $post ) {
116
         foreach( $found_posts as $post ) {
116
             // print_r($args);
117
             // print_r($args);
117
             // print_r($post);
118
             // print_r($post);
118
-            $formatted = default_post_format( $post, true );
119
+            $formatted = default_post_format( $post, false );
119
 
120
 
120
             // For your hero URL
121
             // For your hero URL
121
             $formatted[hero] = get_post_meta( $post->ID, 'hero_header', true );
122
             $formatted[hero] = get_post_meta( $post->ID, 'hero_header', true );
133
         }
134
         }
134
         wp_reset_postdata();
135
         wp_reset_postdata();
135
         // Uncomment to include pagination and query information
136
         // Uncomment to include pagination and query information
136
-        // $collection['_meta'] = $args;
137
+        // $collection['_meta'] = $q;
137
         return $collection;
138
         return $collection;
138
     }
139
     }
139
 }
140
 }

Загрузка…
Отмена
Сохранить