REST API 文档

💡 云策文档标注

概述

本文档定义了 WordPress REST API 中搜索结果的 Schema 结构,并提供了列出搜索结果的端点及其查询参数。它面向开发者,用于理解和控制搜索结果的返回数据。

关键要点

  • Schema 定义了搜索结果记录的字段,包括 id、title、url、type 和 subtype,这些字段默认包含在响应中,除非使用 `_filter` 参数或特定上下文限制。
  • 列出搜索结果的端点为 GET /wp/v2/search,支持通过查询参数如 context、page、per_page、search、type、subtype、exclude 和 include 来控制和过滤响应。
  • 所有字段均为只读,JSON 数据类型包括整数、字符串和 URI 格式,type 和 subtype 字段有预定义的值列表。

📄 原文内容

Schema

The schema defines all the fields that exist within a search result 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 Unique identifier for the object.

JSON data type: integer or string

Read only

Context: view, embed

title The title for the object.

JSON data type: string

Read only

Context: view, embed

url URL to the object.

JSON data type: string,
Format: uri

Read only

Context: view, embed

type Object type.

JSON data type: string

Read only

Context: view, embed

One of: post, term, post-format

subtype Object subtype.

JSON data type: string

Read only

Context: view, embed

One of: post, page, category, post_tag

List Search Results

Query this endpoint to retrieve a collection of search results. The response you receive can be controlled and filtered using the URL query parameters below.

Definition

GET /wp/v2/search

Example Request

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

Arguments

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

Default: view

One of: view, embed

page Current page of the collection.

Default: 1

per_page Maximum number of items to be returned in result set.

Default: 10

search Limit results to those matching a string.
type Limit results to items of an object type.

Default: post

One of: post, term, post-format

subtype Limit results to items of one or more object subtypes.

Default: any

exclude Ensure result set excludes specific IDs.
include Limit result set to specific IDs.