$post_type, 'post_status' => ['publish'], 'posts_per_page' => -1, 'page' => 1 ]; } /** * 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_terms' ) ), ]); } public function get_all_terms( $request ) { $terms = $categories = get_terms($post->post_type . '_type', array( 'orderby' => 'count', 'hide_empty' => 0, )); $taxonomies = get_object_taxonomies($post->post_type); $formatted[terms] = $terms; $formatted[taxonomies] = $taxonomies; return new WP_REST_Response( $this->prepare_all_items_for_response($args), 200 ); } public function prepare_all_items_for_response( $args ) { $collection = []; // https://developer.wordpress.org/reference/functions/get_posts/ foreach( get_posts($args) as $item ) { $formatted = default_post_format( $item, true ); array_push($collection, $formatted); } wp_reset_postdata(); return $collection; } } ?>