REST API 文档

💡 云策文档标注

概述

本文档介绍了 WordPress REST API 中菜单位置(Menu Locations)的架构和端点,包括字段定义和检索方法。面向开发者,用于通过 API 管理菜单位置数据。

关键要点

  • 菜单位置记录包含 name、description 和 menu 字段,均为只读,JSON 数据类型分别为字符串、字符串和整数。
  • 提供两个 REST API 端点:GET /wp/v2/menu-locations 用于检索所有菜单位置,GET /wp/v2/menu-locations/<location> 用于检索特定菜单位置。
  • 支持 context 参数(view、embed、edit)来控制响应中的字段范围,默认值为 view。

代码示例

$ curl https://example.com/wp-json/wp/v2/menu-locations
$ curl https://example.com/wp-json/wp/v2/menu-locations/<location>

📄 原文内容

Schema

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

name The name of the menu location.

JSON data type: string

Read only

Context: embed, view, edit

description The description of the menu location.

JSON data type: string

Read only

Context: embed, view, edit

menu The ID of the assigned menu.

JSON data type: integer

Read only

Context: embed, view, edit

Retrieve a Menu Location

Definition & Example Request

GET /wp/v2/menu-locations

Query this endpoint to retrieve a specific menu location record.

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

Arguments

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

Default: view

One of: view, embed, edit

Retrieve a Menu Location

Definition & Example Request

GET /wp/v2/menu-locations/<location>

Query this endpoint to retrieve a specific menu location record.

$ curl https://example.com/wp-json/wp/v2/menu-locations/<location>

Arguments

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

Default: view

One of: view, embed, edit