add_action('rest_api_init', function () { register_rest_route('art/v1', 'posts/(?P<slug>[a-zA-Z0-9-]+)', [ 'methods' => 'GET', 'callback' => 'art_post', ]);});И в функции укажу какую информацию об этом посте я хочу получить.
function art_post($slug){ $data = []; $args = [ 'post_type' => 'post', 'name' => $slug['slug'], ]; $post = get_posts($args); $id = $post[0]->ID; $get_the_post_thumbnail_url = get_the_post_thumbnail_url($id); // Added to api $data['id'] = $id; $data['title'] = $post[0]->post_title; $data['get_the_post_thumbnail_url'] = $get_the_post_thumbnail_url; $data['content'] = $post[0]->post_content; $data['slug'] = $post[0]->post_name; return $data;}
