REST API 文档

Nav_Menu_Item Revisions

💡 云策文档标注

概述

本文档详细介绍了 Nav_Menu_Item 修订(Revisions)的 REST API 端点,包括其数据模式、字段定义以及如何检索和创建修订记录。面向 WordPress 开发者,用于管理导航菜单项的版本控制。

关键要点

  • Nav_Menu_Item 修订记录包含多个字段,如 author、date、id、parent、title 等,每个字段有 JSON 数据类型、上下文(view、edit、embed)和格式说明。
  • 提供两个主要端点:GET /wp/v2/menu-items/<id>/autosaves 用于检索修订列表,GET /wp/v2/menu-items/<parent>/autosaves/<id> 用于检索特定修订记录。
  • 创建修订使用 POST /wp/v2/menu-items/<id>/autosaves,支持参数如 parent、title、type、status、attr_title、classes、description、menu_order、object、object_id、target、url、xfn、menus 和 meta。
  • 参数 context 控制响应字段范围,可选 view、embed 或 edit,默认值为 view。
  • 部分字段如 preview_link 是只读的,仅在特定上下文中可用。

代码示例

GET /wp/v2/menu-items/<id>/autosaves
$ curl https://example.com/wp-json/wp/v2/menu-items/<id>/autosaves

POST /wp/v2/menu-items/<id>/autosaves
参数示例:parent=123, title="示例菜单项", type="post_type", status="draft"

📄 原文内容

Schema

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

author The ID for the author of the revision.

JSON data type: integer

Context: view, edit, embed

date The date the revision was published, in the site's timezone.

JSON data type: string,
Format: datetime (details)

Context: view, edit, embed

date_gmt The date the revision was published, as GMT.

JSON data type: string,
Format: datetime (details)

Context: view, edit

guid GUID for the revision, as it exists in the database.

JSON data type: string

Context: view, edit

id Unique identifier for the revision.

JSON data type: integer

Context: view, edit, embed

modified The date the revision was last modified, in the site's timezone.

JSON data type: string,
Format: datetime (details)

Context: view, edit

modified_gmt The date the revision was last modified, as GMT.

JSON data type: string,
Format: datetime (details)

Context: view, edit

parent The ID for the parent of the revision.

JSON data type: integer

Context: view, edit, embed

slug An alphanumeric identifier for the revision unique to its type.

JSON data type: string

Context: view, edit, embed

title The title for the object.

JSON data type: string or object

Context: view, edit, embed

Retrieve a Nav_Menu_Item Revision

Definition & Example Request

GET /wp/v2/menu-items/<id>/autosaves

Query this endpoint to retrieve a specific nav_menu_item revision record.

$ curl https://example.com/wp-json/wp/v2/menu-items/<id>/autosaves

Arguments

parent The ID for the parent of the autosave.
context Scope under which the request is made; determines fields present in response.

Default: view

One of: view, embed, edit

Create a Nav_Menu_Item Revision

Arguments

<a href="#schema-parent">parent</a> The ID for the parent of the object.
<a href="#schema-title">title</a> The title for the object.
<a href="#schema-type">type</a> The family of objects originally represented, such as "post_type" or "taxonomy".
One of: taxonomy, post_type, post_type_archive, custom
<a href="#schema-status">status</a> A named status for the object.
One of: publish, future, draft, pending, private
<a href="#schema-attr_title">attr_title</a> Text for the title attribute of the link element for this menu item.
<a href="#schema-classes">classes</a> Class names for the link element of this menu item.
<a href="#schema-description">description</a> The description of this menu item.
<a href="#schema-menu_order">menu_order</a> The DB ID of the nav_menu_item that is this item's menu parent, if any, otherwise 0.
<a href="#schema-object">object</a> The type of object originally represented, such as "category", "post", or "attachment".
<a href="#schema-object_id">object_id</a> The database ID of the original object this menu item represents, for example the ID for posts or the term_id for categories.
<a href="#schema-target">target</a> The target attribute of the link element for this menu item.
One of: _blank,
<a href="#schema-url">url</a> The URL to which this menu item points.
<a href="#schema-xfn">xfn</a> The XFN relationship expressed in the link of this menu item.
<a href="#schema-menus">menus</a> The terms assigned to the object in the nav_menu taxonomy.
<a href="#schema-meta">meta</a> Meta fields.

Definition

POST /wp/v2/menu-items/<id>/autosaves

Retrieve a Nav_Menu_Item Revision

Definition & Example Request

GET /wp/v2/menu-items/<parent>/autosaves/<id>

Query this endpoint to retrieve a specific nav_menu_item revision record.

$ curl https://example.com/wp-json/wp/v2/menu-items/<parent>/autosaves/<id>

Arguments

parent The ID for the parent of the autosave.
id The ID for the autosave.
context Scope under which the request is made; determines fields present in response.

Default: view

One of: view, embed, edit