REST API 文档

💡 云策文档标注

概述

本文档介绍了 WordPress REST API 中分类法(Taxonomies)的架构和端点使用。核心内容包括分类法记录的字段定义,以及如何通过 REST API 检索分类法信息。

关键要点

  • 分类法架构定义了多个字段,如 capabilities、description、hierarchical、labels、name、slug、show_cloud、types、rest_base、rest_namespace 和 visibility,这些字段在响应中默认包含,除非使用 _filter 参数或特定上下文。
  • 所有字段均为只读,JSON 数据类型包括对象、字符串、布尔值和数组,上下文(context)决定了字段的可见性。
  • 提供了两个 REST API 端点:GET /wp/v2/taxonomies 用于检索所有分类法,GET /wp/v2/taxonomies/<taxonomy> 用于检索特定分类法,支持参数如 context 和 type。

代码示例

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

GET /wp/v2/taxonomies/<taxonomy>
$ curl https://example.com/wp-json/wp/v2/taxonomies/<taxonomy>

📄 原文内容

Schema

The schema defines all the fields that exist within a taxonomy record. Any response from these endpoints can be expected to contain the fields below unless the `_filter` query parameter is used or the schema field only appears in a specific context.

capabilities All capabilities used by the taxonomy.

JSON data type: object

Read only

Context: edit

description A human-readable description of the taxonomy.

JSON data type: string

Read only

Context: view, edit

hierarchical Whether or not the taxonomy should have children.

JSON data type: boolean

Read only

Context: view, edit

labels Human-readable labels for the taxonomy for various contexts.

JSON data type: object

Read only

Context: edit

name The title for the taxonomy.

JSON data type: string

Read only

Context: view, edit, embed

slug An alphanumeric identifier for the taxonomy.

JSON data type: string

Read only

Context: view, edit, embed

show_cloud Whether or not the term cloud should be displayed.

JSON data type: boolean

Read only

Context: edit

types Types associated with the taxonomy.

JSON data type: array

Read only

Context: view, edit

rest_base REST base route for the taxonomy.

JSON data type: string

Read only

Context: view, edit, embed

rest_namespace REST namespace route for the taxonomy.

JSON data type: string

Read only

Context: view, edit, embed

visibility The visibility settings for the taxonomy.

JSON data type: object

Read only

Context: edit

Retrieve a Taxonomy

Definition & Example Request

GET /wp/v2/taxonomies

Query this endpoint to retrieve a specific taxonomy record.

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

Arguments

context Scope under which the request is made; determines fields present in response.

Default: view

One of: view, embed, edit

type Limit results to taxonomies associated with a specific post type.

Retrieve a Taxonomy

Definition & Example Request

GET /wp/v2/taxonomies/<taxonomy>

Query this endpoint to retrieve a specific taxonomy record.

$ curl https://example.com/wp-json/wp/v2/taxonomies/<taxonomy>

Arguments

taxonomy An alphanumeric identifier for the taxonomy.
context Scope under which the request is made; determines fields present in response.

Default: view

One of: view, embed, edit