美文网首页
WP插件JSON API

WP插件JSON API

作者: jlnbda3488375 | 来源:发表于2017-02-12 21:28 被阅读89次

info get_recent_posts get_posts get_post get_page get_date_posts get_category_posts get_tag_posts get_author_posts get_search_results get_date_index get_category_index get_tag_index get_author_index get_page_index get_nonce

info

Returns information about JSON API.

    Response
    {
      "status": "ok",
      "json_api_version": "1.0",
      "controllers": [
        "core"
      ]
    }

get_recent_posts

Returns an array of recent posts.
可选:

  • count - determines how many posts per page are returned (default value is 10)

  • page - return a specific page number from the results

  • post_type - used to retrieve custom post types

      Response
      {
        "status": "ok",
        "count": 10,
        "count_total": 79,
        "pages": 7,
        "posts": [
          { ... },
          { ... },
          ...
        ]
      }
    

get_posts


get_post

Returns a single post object.
必须(One of the following is required):

  • Invoking the JSON API implicitly (i.e., ?json=1) on a post URL

  • id or post_id - set to the post's ID

  • slug or post_slug - set to the post's URL slug

      Response
      {
        "status": "ok",
        "post": { ... }
      }
    

get_page

Returns a single page object.
必须(One of the following is required):

  • Invoking the JSON API implicitly (i.e., ?json=1) on a post URL
  • id or post_id - set to the post's ID
  • slug or post_slug - set to the post's URL slug

Optional arguments

  • children - set to a non-empty value to include a recursive hierarchy of child pages

  • post_type - used to retrieve custom post types

      Response
      {
        "status": "ok",
        "post": { ... }
      }
    

Method: get_date_posts

Returns an array of posts/pages in a specific date archive (by day, month, or year).

One of the following is required

  • Invoking the JSON API implicitly (i.e., ?json=1) on a date archive page
  • date - set to a date in the format YYYY or YYYY-MM or YYYY-MM-DD (non-numeric characters are stripped from the var, so YYYYMMDD or YYYY/MM/DD are also valid)

Optional arguments

  • count - determines how many posts per page are returned (default value is 10)

  • page - return a specific page number from the results

  • post_type - used to retrieve custom post types

      Response
      {
        "status": "ok",
        "count": 10,
        "count_total": 79,
        "pages": 7,
        "posts": [
          { ... },
          { ... },
          ...
        ]
      }
    

Method: get_category_posts


Method: get_tag_posts


Method: get_author_posts


Method: get_search_results

Returns an array of posts/pages in response to a search query.

One of the following is required

  • Invoking the JSON API implicitly (i.e., ?json=1) on a search results page
  • search - set to the desired search query

Optional arguments

  • count - determines how many posts per page are returned (default value is 10)

  • page - return a specific page number from the results

  • post_type - used to retrieve custom post types

      Response
      {
        "status": "ok",
        "count": 10,
        "count_total": 79,
        "pages": 7,
        "posts": [
          { ... },
          { ... },
          ...
        ]
      }
    

Method: get_date_index

Returns both an array of date page permalinks and a tree structure representation of the archive.

    Response
    {
      "status": "ok",
      "permalinks": [
        "...",
        "...",
        "..."
      ],
      "tree": {
        "2009": {
          "09": 17,
          "10": 20,
          "11": 7
        }
      }

Note: the tree is arranged by response.tree.[year].[month].[number of posts]


Method: get_category_index


Method: get_tag_index


Method: get_author_index


Method: get_page_index


Method: get_nonce

Returns a WordPress nonce value, required to call some data manipulation methods.

  • controller - the JSON API controller for the method you will use the nonce for

  • method - the method you wish to call (currently create_post is the only method that requires a nonce)

      Response
      {
        "status": "ok",
        "controller": "posts",
        "method": "create_post",
        "nonce": "cefe01efd4"
      }
    

相关参考资料:

  1. JSON API强大的WordPress做API接口插件:http://blog.csdn.net/su_tianbiao/article/details/50622671

相关文章

网友评论

      本文标题:WP插件JSON API

      本文链接:https://www.haomeiwen.com/subject/gzzaittx.html