wp_get_post_terms is difference obj model than the one in rest api response

I got fixed my problem by using the method prepare_item_for_response in WP_REST_Terms_Controller function custome_posts_response(WP_REST_Response $data, WP_POST $post, WP_REST_Request $request) { $newspapers = wp_get_post_terms($post->ID, ‘newspaper’); $categories = wp_get_post_terms($post->ID, ‘category’); $tags = wp_get_post_terms($post->ID, ‘post_tag’); $newspaper_ctrl = new WP_REST_Terms_Controller(‘newspaper’); $category_ctrl = new WP_REST_Terms_Controller(‘category’); $tags_ctrl = new WP_REST_Terms_Controller(‘post_tag’); $newspapers = array_map(function( WP_TERM $newspaper ) use ($newspaper_ctrl, $request) { return … Read more

Creating a custom endpoint for rest, I see the endpoint exists in the wp-json, but the request is returning 404

There’s an issue in your code: The HTTP method is not valid because WP_REST_Server::READABLE is a class constant, hence it should not be wrapped in quotes: register_rest_route( ‘adventapi/v1’, ‘/adventapi/’, array( // ‘methods’ => ‘WP_REST_Server::READABLE’, // wrong // ‘methods’ => “WP_REST_Server::READABLE”, // wrong ‘methods’ => WP_REST_Server::READABLE, // correct // … other args. ) ); You should … Read more