1
我想在不使用任何插件的情況下執行此操作,因爲這些插件都是核心WordPress功能(自定義字段和REST API)。下面是自定義字段的文檔以供參考:如何將WordPress中定義的自定義字段添加到wordpress的其他API響應中
https://codex.wordpress.org/Using_Custom_Fields
這裏是我的WordPress安裝截圖:
這裏是一個職位API響應看起來像目前:
{
"_links": {
"about": [
{
"href": "http://example.com/wp-json/wp/v2/types/post"
}
],
"author": [
{
"embeddable": true,
"href": "http://example.com/wp-json/wp/v2/users/1"
}
],
"collection": [
{
"href": "http://example.com/wp-json/wp/v2/posts"
}
],
"curies": [
{
"href": "https://api.w.org/{rel}",
"name": "wp",
"templated": true
}
],
"replies": [
{
"embeddable": true,
"href": "http://example.com/wp-json/wp/v2/comments?post=21"
}
],
"self": [
{
"href": "http://example.com/wp-json/wp/v2/posts/21"
}
],
"version-history": [
{
"href": "http://example.com/wp-json/wp/v2/posts/21/revisions"
}
],
"wp:attachment": [
{
"href": "http://example.com/wp-json/wp/v2/media?parent=21"
}
],
"wp:featuredmedia": [
{
"embeddable": true,
"href": "http://example.com/wp-json/wp/v2/media/23"
}
],
"wp:term": [
{
"embeddable": true,
"href": "http://example.com/wp-json/wp/v2/categories?post=21",
"taxonomy": "category"
},
{
"embeddable": true,
"href": "http://example.com/wp-json/wp/v2/tags?post=21",
"taxonomy": "post_tag"
}
]
},
"author": 1,
"categories": [
5,
4
],
"comment_status": "open",
"content": {
"protected": false,
"rendered": ""
},
"date": "2017-05-14T15:25:33",
"date_gmt": "2017-05-14T15:25:33",
"excerpt": {
"protected": false,
"rendered": ""
},
"featured_media": 23,
"format": "standard",
"guid": {
"rendered": "http://example.com/?p=21"
},
"id": 21,
"link": "http://example.com/2017/05/14/post/",
"meta": [],
"modified": "2017-05-15T18:17:34",
"modified_gmt": "2017-05-15T18:17:34",
"ping_status": "open",
"slug": "",
"sticky": false,
"tags": [],
"template": "",
"title": {
"rendered": ""
},
"type": "post"
}
萬一它可能是相關的,這裏是我的活動插件:
任何幫助是極大的讚賞。謝謝!
謝謝,這是有道理的。這段代碼應該去哪裏? – quinn
在您的主題功能中,或者如果您在插件功能中使用插件 –