WordPress REST API, how to get /post schema?

16 viewsphpwordpresswordpress rest api
0

I have created a custom endpoint, that basically just grabs a few different posts from each category and returns it. This endpoint works fine, but the schema of each post being returned is not the same as when you just hit the default, built-in /posts endpoint. What do I have to do to keep the schemas consistent?

I have a feeling get_posts is the problem, but I have been doc crawling, and I cant seem to find anything that uses the same schema as /posts does.

// How the endpoint is built.
function anon_content_api_posts($category) {
  $posts = get_posts(
    array(
      'posts_per_page' => 3,
      'tax_query' => array(
          array(
              'taxonomy' => 'content_category',
              'field' => 'term_id',
              'terms' => $category->term_id,
          )
      )
    )
  );
  $posts = array_map('get_extra_post_data', $posts); // just me appending more data to each post.
  return $posts;
}

function anon_content_api_resources() {
  $data = array();

  $categories = get_categories(
    array(
      'taxonomy' => 'content_category',
    )
  );

  foreach($categories as $category) {
    $category->posts = anon_content_api_posts($category);
    array_push($data, $category);
  }

  return $data;
}

Custom endpoint schema

ID: 
author: 
comment_count: 
comment_status: 
featured_image_url: 
filter: 
guid: 
menu_order: 
ping_status: 
pinged: 
post_author: 
post_content: 
post_content_filtered:
post_date: 
post_date_gmt:
post_excerpt:
post_mime_type:
post_modified:
post_modified_gmt:
post_name:
post_parent:
post_password:
post_status:
post_title:
post_type:
to_ping:

Default /posts schema

_links:
author:
categories:
comment_status:
content:
date:
date_gmt:
excerpt:
featured_image_url:
featured_media:
format:
guid:
id:
link:
meta:
modified:
modified_gmt:
ping_status:
slug:
status:
sticky:
task_category:
template:
title:
type:

Any help would be appreciated!