如何从自定义帖子类型与WP Rest Api v1.2.5获取帖子
问题描述:
我想从帖子类型=事件获取帖子,但未显示来自帖子帖子类型的正确帖子,但是来自实际WP-POST如何从自定义帖子类型与WP Rest Api v1.2.5获取帖子
<?php
// Get the JSON
$json = file_get_contents('http://coralgableschamber.org/wp-json/posts?filter[posts_per_page]=1&filter[post_type]=events');
// Convert the JSON to an array of posts
$posts = json_decode($json);
foreach ($posts as $p) {
echo '<p>Title: ' . $p->title . '</p>';
echo '<p>Date: ' . date('F jS', strtotime($p->date)) . '</p>';
// Output the featured image (if there is one)
echo $p->featured_image ? '<amp-img src="' . $p->featured_image->guid . '" width="150" height="110"></amp-img>' : '';
echo '<p>Content: ' . $p->content. '</p>';
}
它显示错误后检查此链接:http://mxcounters.com/coralgables/AMP/front.html
什么是错的,我如何修复它使其工作。
谢谢!
答
现在我想这样,但仍然没有从帖子类型事件中获取帖子 $ json = file_get_contents('http://coralgableschamber.org/wp-json/posts?filter [post_type] = events&filter [posts_per_page] = 1 “); – Xabby
是的,现在工作谢谢@哈尔夫疯了 – Xabby