Skip to main content
edited tags
Link
Johansson
  • 15.4k
  • 11
  • 43
  • 79
Source Link

data returned from get_post($postId) have different keys than wp-json/wp/v2/posts/{postId}

WordPress Devs. I am new to WordPress and Web development. So far WordPress Rest API v2 works well. I was writing a custom API/route/endpoint for my project using the following function.

 get_post($postId);

Here the keys that are return as a response are mainly ID, post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt, post_status, comment_status.

However, the keys obtain from http://techdevfan.com/wp-json/wp/v2/posts are different from the custom API post object mainly id date, date_gmt, guid, modified, status, link, title.

There is completely no problem in serializing both the response. I just want to know is there any alternative to such problem so that there is no ambiguity in the keys for the two cases other than renaming the keys in $post object of a custom endpoint.