WP_REST_Server::READABLE, 'callback' => array( $this, 'get_all_items' ) ), ]); } public function get_all_items( $request ) { $args = array( 'numberposts' => 1, ); return new WP_REST_Response( $this->prepare_all_items_for_response($args), 200 ); } public function prepare_all_items_for_response( $args ) { $collection = array(); $types = [ 'artist', 'episode', 'event', 'exhibition', 'guide', 'object', 'publication', 'technique', 'short', 'post', ]; $q = []; foreach($types as $post_type) { array_push($q, new WP_Query(array( 'numberposts' => 1, 'post_type' => $post_type, 'post_status' => ['publish'], ))); array_push($q, $post_type); $found_post = $q[0]->get_posts(); $formatted = default_post_format( $found_post, false ); $formatted['tried'] = $q[1]; array_push($collection, $formatted); } wp_reset_postdata(); return $collection; // return $types; } } ?>