[英]How to Get Posts From Custom post type with WP Rest Api v1.2.5
I want to get the posts from post type = events but it is not showing the correct posts from events post type but from the actual WP-POST 我想从帖子类型=事件中获取帖子,但它不是从事件帖子类型中显示正确的帖子,而是从实际的WP-POST中显示
<?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>';
}
The event post type have the following posts in it but it is not showing these 事件帖子类型中包含以下帖子,但未显示这些帖子
It is showing wrong post check this link : http://mxcounters.com/coralgables/AMP/front.html 显示错误的帖子,请检查以下链接 : http : //mxcounters.com/coralgables/AMP/front.html
What is wrong and how i can fix to make it work. 怎么了,我该如何解决才能使其正常工作。
Thanks! 谢谢!
Try using http://coralgableschamber.org/wp-json/posts?type=events instead. 尝试改用http://coralgableschamber.org/wp-json/posts?type=events 。
You can look at http://coralgableschamber.org/wp-json/ to see all available paths. 您可以查看http://coralgableschamber.org/wp-json/以查看所有可用路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.