REST API 文档

💡 云策文档标注

概述

本文档介绍了 WordPress REST API 中 Types 端点的 schema 定义和检索方法。Schema 定义了文章类型记录的字段,包括 capabilities、description、hierarchical 等,这些字段在响应中默认出现,除非使用 `_filter` 参数或特定上下文限制。文档还提供了检索所有类型和特定类型的 API 端点、示例请求和参数说明。

关键要点

  • Schema 定义了文章类型记录的字段,如 capabilities(能力)、description(描述)、hierarchical(层级性)、viewable(可查看性)、labels(标签)、name(名称)、slug(别名)、supports(支持特性)、has_archive(归档设置)、taxonomies(分类法)、rest_base(REST 基础路由)、rest_namespace(REST 命名空间)、visibility(可见性设置)和 icon(图标)。
  • 所有字段均为只读,JSON 数据类型包括 object、string、boolean、array 或混合类型,上下文(context)决定了字段在响应中的出现情况,可选值为 view、embed 或 edit。
  • 检索所有文章类型使用 GET /wp/v2/types 端点,检索特定文章类型使用 GET /wp/v2/types/<type> 端点,其中 <type> 是文章类型的标识符。
  • 参数 context 用于指定请求的上下文,默认值为 view,可选值包括 view、embed 和 edit,影响响应中字段的呈现。

📄 原文内容

Schema

The schema defines all the fields that exist within a type 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 post type.

JSON data type: object

Read only

Context: edit

description A human-readable description of the post type.

JSON data type: string

Read only

Context: view, edit

hierarchical Whether or not the post type should have children.

JSON data type: boolean

Read only

Context: view, edit

viewable Whether or not the post type can be viewed.

JSON data type: boolean

Read only

Context: edit

labels Human-readable labels for the post type for various contexts.

JSON data type: object

Read only

Context: edit

name The title for the post type.

JSON data type: string

Read only

Context: view, edit, embed

slug An alphanumeric identifier for the post type.

JSON data type: string

Read only

Context: view, edit, embed

supports All features, supported by the post type.

JSON data type: object

Read only

Context: edit

has_archive If the value is a string, the value will be used as the archive slug. If the value is false the post type has no archive.

JSON data type: string or boolean

Read only

Context: view, edit

taxonomies Taxonomies associated with post type.

JSON data type: array

Read only

Context: view, edit

rest_base REST base route for the post type.

JSON data type: string

Read only

Context: view, edit, embed

rest_namespace REST route's namespace for the post type.

JSON data type: string

Read only

Context: view, edit, embed

visibility The visibility settings for the post type.

JSON data type: object

Read only

Context: edit

icon The icon for the post type.

JSON data type: string or null

Read only

Context: view, edit, embed

Retrieve a Type

Definition & Example Request

GET /wp/v2/types

Query this endpoint to retrieve a specific type record.

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

Arguments

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

Default: view

One of: view, embed, edit

Retrieve a Type

Definition & Example Request

GET /wp/v2/types/<type>

Query this endpoint to retrieve a specific type record.

$ curl https://example.com/wp-json/wp/v2/types/<type>

Arguments

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

Default: view

One of: view, embed, edit