簡體   English   中英

如何使用WP Rest Api v1.2.5從自定義帖子類型獲取帖子

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

我想從帖子類型=事件中獲取帖子,但它不是從事件帖子類型中顯示正確的帖子,而是從實際的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>';    

   }

事件帖子類型中包含以下帖子,但未顯示這些帖子 在此處輸入圖片說明

顯示錯誤的帖子,請檢查以下鏈接http : //mxcounters.com/coralgables/AMP/front.html

怎么了,我該如何解決才能使其正常工作。

謝謝!

嘗試改用http://coralgableschamber.org/wp-json/posts?type=events

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM