カテゴリー

2020.03.27 2020.03.27

TOPICS

翻訳元記事はこちらです。

レスポンスサンプル

カテゴリーリスト

$ curl https://demo.wp-api.org/wp-json/wp/v2/categories
[
  {
    "id": 2,
    "count": 3,
    "description": "Neque quibusdam nihil sequi quia et inventore dolorem dolores et consequuntur nostrum delectus esse cum et voluptatem ut rerum et accusamus quae vel neque laudantium optio rerum asperiores assumenda rerum qui eius neque dolores id quibusdam id optio ut eius dolor qui quas non",
    "link": "https://demo.wp-api.org/category/aut-architecto-nihil/",
    "name": "Aut architecto nihil",
    "slug": "aut-architecto-nihil",
    "taxonomy": "category",
    "parent": 0,
    "meta": [],
    "_links": {
      "self": [
        {
          "href": "https://demo.wp-api.org/wp-json/wp/v2/categories/2"
        }
      ],
      "collection": [
        {
          "href": "https://demo.wp-api.org/wp-json/wp/v2/categories"
        }
      ],
      "about": [
        {
          "href": "https://demo.wp-api.org/wp-json/wp/v2/taxonomies/category"
        }
      ],
      "wp:post_type": [
        {
          "href": "https://demo.wp-api.org/wp-json/wp/v2/posts?categories=2"
        }
      ],
      "curies": [
        {
          "name": "wp",
          "href": "https://api.w.org/{rel}",
          "templated": true
        }
      ]
    }
  },
  {
    "id": 11,
    "count": 7,
    "description": "Rem recusandae velit et incidunt labore qui explicabo veritatis eos quod dolor dolor occaecati nobis in suscipit et quo impedit repellat eius voluptatem",
    "link": "https://demo.wp-api.org/category/facilis-dignissimos/",
    "name": "Facilis dignissimos",
    "slug": "facilis-dignissimos",
    "taxonomy": "category",
    "parent": 0,
    "meta": [],
    "_links": {
      "self": [
        {
          "href": "https://demo.wp-api.org/wp-json/wp/v2/categories/11"
        }
      ],
      "collection": [
        {
          "href": "https://demo.wp-api.org/wp-json/wp/v2/categories"
        }
      ],
      "about": [
        {
          "href": "https://demo.wp-api.org/wp-json/wp/v2/taxonomies/category"
        }
      ],
      "wp:post_type": [
        {
          "href": "https://demo.wp-api.org/wp-json/wp/v2/posts?categories=11"
        }
      ],
      "curies": [
        {
          "name": "wp",
          "href": "https://api.w.org/{rel}",
          "templated": true
        }
      ]
    }
  },
  {
    "id": 1,
    "count": 7,
    "description": "",
    "link": "https://demo.wp-api.org/category/uncategorized/",
    "name": "Uncategorized",
    "slug": "uncategorized",
    "taxonomy": "category",
    "parent": 0,
    "meta": [],
    "_links": {
      "self": [
        {
          "href": "https://demo.wp-api.org/wp-json/wp/v2/categories/1"
        }
      ],
      "collection": [
        {
          "href": "https://demo.wp-api.org/wp-json/wp/v2/categories"
        }
      ],
      "about": [
        {
          "href": "https://demo.wp-api.org/wp-json/wp/v2/taxonomies/category"
        }
      ],
      "wp:post_type": [
        {
          "href": "https://demo.wp-api.org/wp-json/wp/v2/posts?categories=1"
        }
      ],
      "curies": [
        {
          "name": "wp",
          "href": "https://api.w.org/{rel}",
          "templated": true
        }
      ]
    }
  }
]

スキーマ

カテゴリーオブジェクトに定義されているフィールドの一覧です。

id
int型
タームのID
読み取り専用
Context: view, embed, edit
count
int型
対象のタームで公開されている投稿の数
読み取り専用
Context: view, edit
description
string型

タームのHTMLの説明
Context: view, edit
link
string型
url
タームのURL
読み取り専用
Context: view, embed, edit
name
string型
タームのHTMLタイトル
Context: view, embed, edit
slug
string型
タームのスラッグ
Context: view, embed, edit
taxonomy
string型
タームのタイプ
読み取り専用
Context: view, embed, edit
例:category, post_tag, nav_menu, link_category, post_format
parent
int型
親タームID
Context: view, edit
meta
object
メタフィールド
Context: view, edit

リクエスト例

$ curl -X OPTIONS -i https://example.com/wp-json/wp/v2/categories

カテゴリーリスト

引数

contextリクエストが行われるスコープ。レスポンスに存在するフィールドを決定する。
デフォルト:view
例:view, embed, edit
page現在のページ数
デフォルト:1
per_page1ページの件数
デフォルト:10
search文字列にマッチする結果に絞り込む
exclude特定のIDのカテゴリーを除外する
include指定されたIDのカテゴリーに絞り込む
orderソート順を昇順か降順か決める
デフォルト:asc
例:asc, desc
orderbyソート順の基準を決める
デフォルト:name
例:id, include, name, slug, include_slugs, term_group, description, count
hide_empty投稿で使われていないカテゴリーを表示するかどうか
parent特定の親カテゴリーのみに絞り込む
post特定の投稿のカテゴリーのみに絞り込む
slugカテゴリーをslugで絞り込む

定義

GET /wp/v2/categories

リクエスト例

$ curl https://example.com/wp-json/wp/v2/categories

カテゴリーの作成

引数

descriptionタームのHTMLの説明
nameタームの名前
必須項目
slugタームのスラッグ
parent親タームのID
metaメタフィールド

定義

POST /wp/v2/categories

IDを指定してカテゴリーを取得

引数

idタームのID
contextリクエストが行われるスコープ。レスポンスに存在するフィールドを決定する。
デフォルト:view
例:view, embed, edit

定義

GET /wp/v2/categories/<id>

リクエスト例

$ curl https://example.com/wp-json/wp/v2/categories/<id>

カテゴリーの更新

引数

idタームID
descriptionタームの説明
nameタームのタイトル
slugタームのスラッグ
parent親タームID
metaメタフィールド

定義

POST /wp/v2/categories/<id>

カテゴリーの削除

引数

idタームのID
forceゴミ箱に入れず完全に削除するかどうか

定義

DELETE /wp/v2/categories/<id>

リクエスト例

$ curl -X DELETE https://example.com/wp-json/wp/v2/categories/<id>