$data['id'] ); $the_query = new WP_Query( $args ); if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); $output = ''; return json_encode( $output ); endwhile; else : return null; endif; // if ( empty( $posts ) ) { // return null; // } // return $posts[0]->post_title; } add_action( 'rest_api_init', function () { register_rest_route( 'caos/v1', '/metadata/(?P\d+)', array( 'methods' => 'GET', 'callback' => 'my_awesome_func', /*'args' => array( 'id' => array( 'validate_callback' => 'is_numeric' ), ),*/ ) ); } );