本文档详细介绍了 WordPress 模板的 REST API 端点,包括模板记录的 Schema 定义和 CRUD 操作。Schema 定义了模板的所有字段,如 id、slug、type 等,并说明了其 JSON 数据类型、只读属性和上下文。文档还提供了检索、创建、更新和删除模板的具体 API 端点、参数和示例请求。
// 检索所有模板
$ curl https://example.com/wp-json/wp/v2/templates
// 创建模板
POST /wp/v2/templates
参数: slug(必需), theme, type, content, title, description, status, author
// 删除模板
$ curl -X DELETE https://example.com/wp-json/wp/v2/templates/<id> The schema defines all the fields that exist within a template 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.
id
|
ID of template.
JSON data type: string Read only Context: |
slug
|
Unique slug identifying the template.
JSON data type: string Context: |
theme
|
Theme identifier for the template.
JSON data type: string Context: |
type
|
Type of template.
JSON data type: string Context: |
source
|
Source of template
JSON data type: string Read only Context: |
origin
|
Source of a customized template
JSON data type: string Read only Context: |
content
|
Content of template.
JSON data type: object or string Context: |
title
|
Title of template.
JSON data type: object or string Context: |
description
|
Description of template.
JSON data type: string Context: |
status
|
Status of template.
JSON data type: string Context: One of: |
wp_id
|
Post ID.
JSON data type: integer Read only Context: |
has_theme_file
|
Theme file exists.
JSON data type: bool Read only Context: |
author
|
The ID for the author of the template.
JSON data type: integer Context: |
modified
|
The date the template was last modified, in the site's timezone.
JSON data type: string, Read only Context: |
is_custom
|
Whether a template is a custom template.
JSON data type: bool Read only Context: |
GET /wp/v2/templates
Query this endpoint to retrieve a specific template record.
$ curl https://example.com/wp-json/wp/v2/templates
context
|
Scope under which the request is made; determines fields present in response.
Default: One of: |
wp_id
|
Limit to the specified post id. |
area
|
Limit to the specified template part area. |
post_type
|
Post type to get the templates for. |
<a href="#schema-slug">slug</a>
|
Unique slug identifying the template.
Required: 1 |
<a href="#schema-theme">theme</a>
|
Theme identifier for the template. |
<a href="#schema-type">type</a>
|
Type of template. |
<a href="#schema-content">content</a>
|
Content of template. |
<a href="#schema-title">title</a>
|
Title of template. |
<a href="#schema-description">description</a>
|
Description of template. |
<a href="#schema-status">status</a>
|
Status of template.
Default: One of: |
<a href="#schema-author">author</a>
|
The ID for the author of the template. |
POST /wp/v2/templates
GET /wp/v2/templates/<id>?)[/w%-]+)
Query this endpoint to retrieve a specific template record.
$ curl https://example.com/wp-json/wp/v2/templates/<id>?)[/w%-]+)
id
|
The id of a template |
context
|
Scope under which the request is made; determines fields present in response.
Default: One of: |
<a href="#schema-id">id</a>
|
The id of a template |
<a href="#schema-slug">slug</a>
|
Unique slug identifying the template. |
<a href="#schema-theme">theme</a>
|
Theme identifier for the template. |
<a href="#schema-type">type</a>
|
Type of template. |
<a href="#schema-content">content</a>
|
Content of template. |
<a href="#schema-title">title</a>
|
Title of template. |
<a href="#schema-description">description</a>
|
Description of template. |
<a href="#schema-status">status</a>
|
Status of template. One of: publish, future, draft, pending, private
|
<a href="#schema-author">author</a>
|
The ID for the author of the template. |
POST /wp/v2/templates/<id>?)[/w%-]+)
id
|
The id of a template |
force
|
Whether to bypass Trash and force deletion. |
DELETE /wp/v2/templates/<id>?)[/w%-]+)
$ curl -X DELETE https://example.com/wp-json/wp/v2/templates/<id>?)[/w%-]+)