您可以查看 WP REST API (http://v2.wp-api.org)。这正是您正在寻找的。使用 WP REST API,您可以从您管理的任何站点获取帖子的 EVERY 元素,并将其显示在任何其他站点上。 (但你也应该实现某种形式的身份验证!)
示例请求:
http://www.example.com/wp/wp-json/wp/v2/venue
“venue”是我在实际代码中使用的自定义帖子类型。发出示例请求以从站点获取所有场所。
示例响应:
[
{
"id": 20,
"date": "2016-06-08T16:37:23",
"date_gmt": "2016-06-08T16:37:23",
"guid": {
"rendered": "http://www.example.com/wp/?post_type=venue&p=20"
},
"modified": "2016-06-20T11:45:22",
"modified_gmt": "2016-06-20T11:45:22",
"slug": "aquarium-club",
"type": "venue",
"link": "http://www.example.com/wp/venue/aquarium-club/",
"title": {
"rendered": "Aquarium Club"
},
"content": {
"rendered": "<p>Aquarium Club. That’s OK. 7765e546uzfkjglh</p>\n<p> </p>\n<style>\n.gmap-iframe-container {\nmax-width: 100%;\n}\n.gmap-iframe {\nwidth: 100%;\nheight: 200px;\nmin-width:100%;\n}\n</style>\n<div class=\"gmap-iframe-container\">\n<iframe src=\"https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d2695.565888030695!2d19.052103115616678!3d47.49836967917771!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x4741dc402a04eee3%3A0x6869564cd433693c!2sAkv%C3%A1rium+Klub!5e0!3m2!1shu!2shu!4v1466147278469\" frameborder=\"0\" style=\"border:0\" allowfullscreen class=\"gmap-iframe\"></iframe></p>\n"
},
"excerpt": {
"rendered": "<p>Aquarium Club. That’s OK. 7765e546uzfkjglh </p>\n"
},
"featured_media": 0,
"menu_order": 0,
"format": "standard",
"tags": [],
"meta_data": {
"youtube_embed": "https://www.youtube.com/embed/xBW7DglTDGs"
},
"_links": {
"self": [
{
"href": "http://www.example.com/wp/wp-json/wp/v2/venue/20"
}
],
"collection": [
{
"href": "http://www.example.com/wp/wp-json/wp/v2/venue"
}
],
"about": [
{
"href": "http://www.example.com/wp/wp-json/wp/v2/types/venue"
}
],
"wp:attachment": [
{
"href": "http://www.example.com/wp/wp-json/wp/v2/media?parent=20"
}
],
"wp:term": [
{
"taxonomy": "post_tag",
"embeddable": true,
"href": "http://www.example.com/wp/wp-json/wp/v2/tags?post=20"
}
],
"curies": [
{
"name": "wp",
"href": "https://api.w.org/{rel}",
"templated": true
}
]
}
},
{
"id": 18,
"date": "2016-06-08T15:55:04",
"date_gmt": "2016-06-08T15:55:04",
"guid": {
"rendered": "http://www.example.com/wp/?post_type=venue&p=18"
},
"modified": "2016-06-08T15:55:04",
"modified_gmt": "2016-06-08T15:55:04",
"slug": "durer-kert",
"type": "venue",
"link": "http://www.example.com/wp/venue/durer-kert/",
"title": {
"rendered": "Dürer Kert"
},
"content": {
"rendered": ""
},
"excerpt": {
"rendered": ""
},
"featured_media": 19,
"menu_order": 0,
"format": "standard",
"tags": [],
"meta_data": {
"youtube_embed": "https://www.youtube.com/embed/w9saGGpnKlk"
},
"_links": {
"self": [
{
"href": "http://www.example.com/wp/wp-json/wp/v2/venue/18"
}
],
"collection": [
{
"href": "http://www.example.com/wp/wp-json/wp/v2/venue"
}
],
"about": [
{
"href": "http://www.example.com/wp/wp-json/wp/v2/types/venue"
}
],
"wp:featuredmedia": [
{
"embeddable": true,
"href": "http://www.example.com/wp/wp-json/wp/v2/media/19"
}
],
"wp:attachment": [
{
"href": "http://www.example.com/wp/wp-json/wp/v2/media?parent=18"
}
],
"wp:term": [
{
"taxonomy": "post_tag",
"embeddable": true,
"href": "http://www.example.com/wp/wp-json/wp/v2/tags?post=18"
}
],
"curies": [
{
"name": "wp",
"href": "https://api.w.org/{rel}",
"templated": true
}
]
}
},
{
"id": 15,
"date": "2016-06-08T14:52:40",
"date_gmt": "2016-06-08T14:52:40",
"guid": {
"rendered": "http://www.example.com/wp/?post_type=venue&p=15"
},
"modified": "2016-06-08T15:41:27",
"modified_gmt": "2016-06-08T15:41:27",
"slug": "kobuci-kert",
"type": "venue",
"link": "http://www.example.com/wp/venue/kobuci-kert/",
"title": {
"rendered": "KOBUCI Kert"
},
"content": {
"rendered": "<p>This is KOBUCI Kert.</p>\n"
},
"excerpt": {
"rendered": "<p>This is KOBUCI Kert.</p>\n"
},
"featured_media": 17,
"menu_order": 0,
"format": "standard",
"tags": [],
"meta_data": {
"youtube_embed": "https://www.youtube.com/embed/zwNBKh6ghOY"
},
"_links": {
"self": [
{
"href": "http://www.example.com/wp/wp-json/wp/v2/venue/15"
}
],
"collection": [
{
"href": "http://www.example.com/wp/wp-json/wp/v2/venue"
}
],
"about": [
{
"href": "http://www.example.com/wp/wp-json/wp/v2/types/venue"
}
],
"wp:featuredmedia": [
{
"embeddable": true,
"href": "http://www.example.com/wp/wp-json/wp/v2/media/17"
}
],
"wp:attachment": [
{
"href": "http://www.example.com/wp/wp-json/wp/v2/media?parent=15"
}
],
"wp:term": [
{
"taxonomy": "post_tag",
"embeddable": true,
"href": "http://www.example.com/wp/wp-json/wp/v2/tags?post=15"
}
],
"curies": [
{
"name": "wp",
"href": "https://api.w.org/{rel}",
"templated": true
}
]
}
},
{
"id": 13,
"date": "2016-06-08T14:12:38",
"date_gmt": "2016-06-08T14:12:38",
"guid": {
"rendered": "http://www.example.com/wp/?post_type=venue&p=13"
},
"modified": "2016-06-08T14:12:38",
"modified_gmt": "2016-06-08T14:12:38",
"slug": "mupa",
"type": "venue",
"link": "http://www.example.com/wp/venue/mupa/",
"title": {
"rendered": "MÜPA"
},
"content": {
"rendered": "<p>MÜPA is MÜPA. Not bad from a building, is it? A lot of concerts and stuff.</p>\n"
},
"excerpt": {
"rendered": "<p>MÜPA is MÜPA. Not bad from a building, is it? A lot of concerts and stuff.</p>\n"
},
"featured_media": 14,
"menu_order": 0,
"format": "standard",
"tags": [],
"meta_data": {
"youtube_embed": "https://www.youtube.com/embed/YnOW2rUXuSg"
},
"_links": {
"self": [
{
"href": "http://www.example.com/wp/wp-json/wp/v2/venue/13"
}
],
"collection": [
{
"href": "http://www.example.com/wp/wp-json/wp/v2/venue"
}
],
"about": [
{
"href": "http://www.example.com/wp/wp-json/wp/v2/types/venue"
}
],
"wp:featuredmedia": [
{
"embeddable": true,
"href": "http://www.example.com/wp/wp-json/wp/v2/media/14"
}
],
"wp:attachment": [
{
"href": "http://www.example.com/wp/wp-json/wp/v2/media?parent=13"
}
],
"wp:term": [
{
"taxonomy": "post_tag",
"embeddable": true,
"href": "http://www.example.com/wp/wp-json/wp/v2/tags?post=13"
}
],
"curies": [
{
"name": "wp",
"href": "https://api.w.org/{rel}",
"templated": true
}
]
}
},
{
"id": 8,
"date": "2016-06-07T08:36:40",
"date_gmt": "2016-06-07T08:36:40",
"guid": {
"rendered": "http://www.example.com/wp/?post_type=venue&p=8"
},
"modified": "2016-06-08T13:22:39",
"modified_gmt": "2016-06-08T13:22:39",
"slug": "some-venue",
"type": "venue",
"link": "http://www.example.com/wp/venue/some-venue/",
"title": {
"rendered": "National Concert Hall"
},
"content": {
"rendered": "<p>This is the next venue for REST API. Just to see more than one. This should be the general description of this venue. This is the venue – what is it? 5324</p>\n"
},
"excerpt": {
"rendered": "<p>This is the next venue for REST API. Just to see more than one. This should be the general description of this venue. This is the venue – what is it? 5324</p>\n"
},
"featured_media": 9,
"menu_order": 0,
"format": "standard",
"tags": [],
"meta_data": {
"youtube_embed": "https://www.youtube.com/embed/camVVzjGheQ"
},
"_links": {
"self": [
{
"href": "http://www.example.com/wp/wp-json/wp/v2/venue/8"
}
],
"collection": [
{
"href": "http://www.example.com/wp/wp-json/wp/v2/venue"
}
],
"about": [
{
"href": "http://www.example.com/wp/wp-json/wp/v2/types/venue"
}
],
"wp:featuredmedia": [
{
"embeddable": true,
"href": "http://www.example.com/wp/wp-json/wp/v2/media/9"
}
],
"wp:attachment": [
{
"href": "http://www.example.com/wp/wp-json/wp/v2/media?parent=8"
}
],
"wp:term": [
{
"taxonomy": "post_tag",
"embeddable": true,
"href": "http://www.example.com/wp/wp-json/wp/v2/tags?post=8"
}
],
"curies": [
{
"name": "wp",
"href": "https://api.w.org/{rel}",
"templated": true
}
]
}
},
{
"id": 7,
"date": "2016-06-07T08:33:13",
"date_gmt": "2016-06-07T08:33:13",
"guid": {
"rendered": "http://www.example.com/wp/?post_type=venue&p=7"
},
"modified": "2016-06-08T13:20:27",
"modified_gmt": "2016-06-08T13:20:27",
"slug": "orchestra-hall",
"type": "venue",
"link": "http://www.example.com/wp/venue/orchestra-hall/",
"title": {
"rendered": "Music Academy"
},
"content": {
"rendered": "<p>This is a venue – it is made of a custom post type, and I get it with REST API.</p>\n"
},
"excerpt": {
"rendered": "<p>This is a venue – it is made of a custom post type, and I get it with REST API.</p>\n"
},
"featured_media": 11,
"menu_order": 0,
"format": "standard",
"tags": [],
"meta_data": {
"youtube_embed": "https://www.youtube.com/embed/ZL6BFCxNGZ8"
},
"_links": {
"self": [
{
"href": "http://www.example.com/wp/wp-json/wp/v2/venue/7"
}
],
"collection": [
{
"href": "http://www.example.com/wp/wp-json/wp/v2/venue"
}
],
"about": [
{
"href": "http://www.example.com/wp/wp-json/wp/v2/types/venue"
}
],
"wp:featuredmedia": [
{
"embeddable": true,
"href": "http://www.example.com/wp/wp-json/wp/v2/media/11"
}
],
"wp:attachment": [
{
"href": "http://www.example.com/wp/wp-json/wp/v2/media?parent=7"
}
],
"wp:term": [
{
"taxonomy": "post_tag",
"embeddable": true,
"href": "http://www.example.com/wp/wp-json/wp/v2/tags?post=7"
}
],
"curies": [
{
"name": "wp",
"href": "https://api.w.org/{rel}",
"templated": true
}
]
}
}
]
注意:
-- 上面的示例结果是根据我的需要定制的 - 所以你可能会看到一些其他的结果。
-- 单个场地的请求看起来像这样:
http://www.example.com/wp/wp-json/wp/v2/venue/20
如您所见,您可以从其他站点获取所需的每条信息 - 您甚至可以根据自己的喜好自定义响应。