admin管理员组

文章数量:1296401

I'd like to be able to return the most recent Wordpress post from my blog using the WP-API (Version 2).

I can't work out what to put after:

/wp-json/wp/v2/

Any help is much appreciated. - Thanks.

I'd like to be able to return the most recent Wordpress post from my blog using the WP-API (Version 2).

I can't work out what to put after:

/wp-json/wp/v2/

Any help is much appreciated. - Thanks.

Share Improve this question asked Nov 28, 2015 at 18:25 Tristan KirkpatrickTristan Kirkpatrick 1552 silver badges11 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 4

Try this - /wp-json/wp/v2/posts?filter[posts_per_page]=1

According to the docs you specify the number of records to return in one request with the parameter per_page so /wp/v2/posts?per_page=1 will return only the first post.

public Page: string = "posts?per_page=num&offset=num&_embed&category_id=num';";

'categories=num'be used alternatively.

Latest Posts with Restful API


This very simple but useful plugin can help with rewrite ajax with cache ability:

Installation (step by step):

In your WordPress website admin panel

  1. Go to Plugins.
  2. Click on Add new.
  3. Search for "restful api".
  4. install "Latest Posts with Restful API" and Activate it.
  5. At the Settings -> Permalink JUST CLICK SAVE to update site permalink address.

You can :

  1. Show latest posts + category name and post featured Image
(site_URL)/api/latestposts/(Number of POSTs - like 30)
  1. Get one post data + category name and post featured Image
 (site_URL)/api/getpost/(post ID)
  1. Get one VIP category post called "mobile_app_more"
 (site_URL)/api/moretab/1

Download Latest Posts with Restful API

Plugin GitHub Page

Hope this help : ) especially when "wp-json" is disable by firewall plugin!


本文标签: javascriptGet most recent post using WPAPI JSStack Overflow