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; } } ?>