| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- // include('formats.php');
-
- class Make_Sticky_Endpoint extends WP_REST_Controller {
- /**
- * Register the routes for the objects of the controller.
- */
- public function register_custom_route($route) {
- $version = '2';
- $namespace = 'craft/v' . $version;
-
- register_rest_route( $namespace, '/' . $route, [
- array(
- 'methods' => WP_REST_Server::READABLE,
- 'callback' => array( $this, 'get_all_items' )
- ),
- ]);
- }
- public function get_all_items( $request ) {
- $args = array(
- 'numberposts' => 20,
- 'post_type' => [
- 'artist',
- 'episode',
- 'event',
- 'exhibition',
- 'guide',
- 'object',
- 'publication',
- 'technique',
- 'short',
- 'post',
- 'page'
- ],
- 'meta_query' => [array(
- 'key' => 'is_sticky',
- 'value' => 'on',
- 'compare' => 'LIKE'
- )]
- );
-
- return new WP_REST_Response( $this->prepare_all_items_for_response($args), 200 );
- }
- public function prepare_all_items_for_response( $args ) {
- $collection = array();
-
- // https://developer.wordpress.org/reference/functions/get_posts/
- foreach( get_posts($args) as $item ) {
- $collection[$item->ID] = default_post_format( $item, true );
- }
- wp_reset_postdata();
-
- return $collection;
- }
- }
-
- ?>
|