|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+<?php
|
|
|
2
|
+// include('formats.php');
|
|
|
3
|
+
|
|
|
4
|
+class Make_Sticky_Endpoint extends WP_REST_Controller {
|
|
|
5
|
+ /**
|
|
|
6
|
+ * Register the routes for the objects of the controller.
|
|
|
7
|
+ */
|
|
|
8
|
+ public function register_custom_route($route) {
|
|
|
9
|
+ $version = '2';
|
|
|
10
|
+ $namespace = 'craft/v' . $version;
|
|
|
11
|
+
|
|
|
12
|
+ register_rest_route( $namespace, '/' . $route, [
|
|
|
13
|
+ array(
|
|
|
14
|
+ 'methods' => WP_REST_Server::READABLE,
|
|
|
15
|
+ 'callback' => array( $this, 'get_all_items' )
|
|
|
16
|
+ ),
|
|
|
17
|
+ ]);
|
|
|
18
|
+ }
|
|
|
19
|
+ public function get_all_items( $request ) {
|
|
|
20
|
+ $args = array(
|
|
|
21
|
+ 'numberposts' => 20,
|
|
|
22
|
+ 'post_type' => [
|
|
|
23
|
+ 'artist',
|
|
|
24
|
+ 'episode',
|
|
|
25
|
+ 'event',
|
|
|
26
|
+ 'exhibition',
|
|
|
27
|
+ 'post',
|
|
|
28
|
+ 'page'
|
|
|
29
|
+ ],
|
|
|
30
|
+ 'meta_query' => [array(
|
|
|
31
|
+ 'key' => 'is_sticky',
|
|
|
32
|
+ 'value' => 'on',
|
|
|
33
|
+ 'compare' => 'LIKE'
|
|
|
34
|
+ )]
|
|
|
35
|
+ );
|
|
|
36
|
+
|
|
|
37
|
+ return new WP_REST_Response( $this->prepare_all_items_for_response($args), 200 );
|
|
|
38
|
+ }
|
|
|
39
|
+ public function prepare_all_items_for_response( $args ) {
|
|
|
40
|
+ $collection = array();
|
|
|
41
|
+
|
|
|
42
|
+ // https://developer.wordpress.org/reference/functions/get_posts/
|
|
|
43
|
+ foreach( get_posts($args) as $item ) {
|
|
|
44
|
+ $collection[$item->ID] = default_post_format( $item, true );
|
|
|
45
|
+ }
|
|
|
46
|
+ wp_reset_postdata();
|
|
|
47
|
+
|
|
|
48
|
+ return $collection;
|
|
|
49
|
+ }
|
|
|
50
|
+}
|
|
|
51
|
+
|
|
|
52
|
+?>
|