如何使用 WP Rest Api v1.2.5 从自定义 post 类型获取帖子

How to Get Posts From Custom post type with WP Rest Api v1.2.5

我想从 post type = events 中获取 posts 但它没有显示正确的 posts from events post type 而是从实际的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>';    

   }

事件 post 类型中包含以下 post,但未显示这些

显示错误 post 检查这个 link: http://mxcounters.com/coralgables/AMP/front.html

出了什么问题,我该如何解决才能使其正常工作。

谢谢!

请尝试使用 http://coralgableschamber.org/wp-json/posts?type=events

您可以查看 http://coralgableschamber.org/wp-json/ 以查看所有可用路径。