| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php
- // include('formats.php');
-
- class Make_Terms_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_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;
- }
- }
-
- ?>
|