メインコンテンツまでスキップ

WP REST APIから返ってくるデータ構造

投稿

通常の投稿

投稿の中身であるcontent<p>タグなどWordPressで埋め込んだものがHTML要素として入っている

WordPress側でつけたClass名なども入る

_linksの中身はリンクの集合になっている

{
id: 1,
date: '2024-04-25T18:59:05',
date_gmt: '2024-04-25T09:59:05',
guid: { rendered: 'http://localhost:8000/?p=1' },
modified: '2024-04-25T18:59:05',
modified_gmt: '2024-04-25T09:59:05',
slug: 'hello-world',
status: 'publish',
type: 'post',
link: 'http://localhost:8000/hello-world/',
title: { rendered: 'Hello world!' },
content: {
rendered: '\n<p>WordPress へようこそ。こちらは最初の投稿です。編集または削除し、コンテンツ作成を始めてください。</p>\n',
protected: false
},
excerpt: {
rendered: '<p>WordPress へようこそ。こちらは最初の投稿です。編集または削除し、コンテンツ作成を始めてください。</p>\n',
protected: false
},
author: 1,
featured_media: 0,
comment_status: 'open',
ping_status: 'open',
sticky: false,
template: '',
format: 'standard',
meta: { footnotes: '' },
categories: [ 1 ],
tags: [],
_links: {
self: [ [Object] ],
collection: [ [Object] ],
about: [ [Object] ],
author: [ [Object] ],
replies: [ [Object] ],
'version-history': [ [Object] ],
'wp:attachment': [ [Object] ],
'wp:term': [ [Object], [Object] ],
curies: [ [Object] ]
}
}

カスタム投稿タイプ

通常の投稿オブジェクトより少ないが、カスタム投稿タイプを作成する際にほぼ最低限のものだと下記のようになる

{
id: 40,
date: '2024-05-07T18:22:41',
date_gmt: '2024-05-07T09:22:41',
guid: { rendered: 'http://localhost:8000/?post_type=news&#038;p=40' },
modified: '2024-05-07T18:22:41',
modified_gmt: '2024-05-07T09:22:41',
slug: '%e3%81%8a%e7%9f%a5%e3%82%89%e3%81%9b%ef%bc%91',
status: 'publish',
type: 'news',
link: 'http://localhost:8000/news/%e3%81%8a%e7%9f%a5%e3%82%89%e3%81%9b%ef%bc%91/',
title: { rendered: 'お知らせ1' },
content: { rendered: '', protected: false },
featured_media: 0,
template: '',
_links: {
self: [ [Object] ],
collection: [ [Object] ],
about: [ [Object] ],
'version-history': [ [Object] ],
'predecessor-version': [ [Object] ],
'wp:attachment': [ [Object] ],
curies: [ [Object] ]
}
}