Search

This route allows searching across all content in WordPress. Added in WP 5.0.

Possible routes (endpoints are described below):

/wp/v2/search

Controller class: WP_REST_Search_Controller{}

Resource schema

The schema shows all fields that exist for the object: the object fields that the request will return.

Параметр Контекст Описание
id
integer/string readonly
view, embed Unique identifier for the object.
title
string readonly
view, embed The title for the object.
url
string readonly
view, embed URL to the object.
type
string readonly
view, embed Object type.
subtype
string readonly
view, embed Object subtype.

Route description

An OPTIONS request to the route will return a full description of this route: endpoints, their parameters, schema.

$ curl -X OPTIONS -i http://demo.wp-api.org/wp-json/wp/v2/search
GitHub
{
    "namespace": "wp/v2",
    "methods": [
        "GET"
    ],
    "endpoints": [
        {
            "methods": [
                "GET"
            ],
            "args": {
                "context": {
                    "required": false,
                    "default": "view",
                    "enum": [
                        "view",
                        "embed"
                    ],
                    "description": "Scope under which the request is made; determines fields present in response.",
                    "type": "string"
                },
                "page": {
                    "required": false,
                    "default": 1,
                    "description": "Current page of the collection.",
                    "type": "integer"
                },
                "per_page": {
                    "required": false,
                    "default": 10,
                    "description": "Maximum number of items to be returned in result set.",
                    "type": "integer"
                },
                "search": {
                    "required": false,
                    "description": "Limit results to those matching a string.",
                    "type": "string"
                },
                "type": {
                    "required": false,
                    "default": "post",
                    "enum": [
                        "post"
                    ],
                    "description": "Limit results to items of an object type.",
                    "type": "string"
                },
                "subtype": {
                    "required": false,
                    "default": "any",
                    "description": "Limit results to items of one or more object subtypes.",
                    "type": "array",
                    "items": {
                        "enum": [
                            "post",
                            "page",
                            "any"
                        ],
                        "type": "string"
                    }
                }
            }
        }
    ],
    "schema": {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "title": "search-result",
        "type": "object",
        "properties": {
            "id": {
                "description": "Unique identifier for the object.",
                "type": "integer",
                "context": [
                    "view",
                    "embed"
                ],
                "readonly": true
            },
            "title": {
                "description": "The title for the object.",
                "type": "string",
                "context": [
                    "view",
                    "embed"
                ],
                "readonly": true
            },
            "url": {
                "description": "URL to the object.",
                "type": "string",
                "format": "uri",
                "context": [
                    "view",
                    "embed"
                ],
                "readonly": true
            },
            "type": {
                "description": "Object type.",
                "type": "string",
                "enum": [
                    "post"
                ],
                "context": [
                    "view",
                    "embed"
                ],
                "readonly": true
            },
            "subtype": {
                "description": "Object subtype.",
                "type": "string",
                "enum": [
                    "post",
                    "page"
                ],
                "context": [
                    "view",
                    "embed"
                ],
                "readonly": true
            }
        }
    },
    "_links": {
        "self": "http://wptest.ru/wp-json/wp/v2/search"
    }
}

Request type

GET /wp-json/wp/v2/search

Request parameters

"context": {
	"required": false,
	"default": "view",
	"enum": [
		"view",
		"embed"
	],
	"description": "Scope under which the request is made; determines fields present in response.",
	"type": "string"
},
"page": {
	"required": false,
	"default": 1,
	"description": "Current page of the collection.",
	"type": "integer"
},
"per_page": {
	"required": false,
	"default": 10,
	"description": "Maximum number of items to be returned in result set.",
	"type": "integer"
},
"search": {
	"required": false,
	"description": "Limit results to those matching a string.",
	"type": "string"
},
"type": {
	"required": false,
	"default": "post",
	"enum": [
		"post"
	],
	"description": "Limit results to items of an object type.",
	"type": "string"
},
"subtype": {
	"required": false,
	"default": "any",
	"description": "Limit results to items of one or more object subtypes.",
	"type": "array",
	"items": {
		"enum": [
			"post",
			"page",
			"any"
		],
		"type": "string"
	}
}

Example request

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

Response:

[
	{
		"id": 1,
		"title": "Hello world!",
		"url": "https://demo.wp-api.org/2017/05/23/hello-world/",
		"type": "post",
		"subtype": "post",
		"_links": {
			"self": [
				{
					"embeddable": true,
					"href": "https://demo.wp-api.org/wp-json/wp/v2/posts/1"
				}
			],
			"about": [
				{
					"href": "https://demo.wp-api.org/wp-json/wp/v2/types/post"
				}
			],
			"collection": [
				{
					"href": "https://demo.wp-api.org/wp-json/wp/v2/search"
				}
			]
		}
	},
	{
		"id": 2,
		"title": "Sample Page",
		"url": "https://demo.wp-api.org/sample-page/",
		"type": "post",
		"subtype": "page",
		"_links": {
			"self": [
				{
					"embeddable": true,
					"href": "https://demo.wp-api.org/wp-json/wp/v2/pages/2"
				}
			],
			"about": [
				{
					"href": "https://demo.wp-api.org/wp-json/wp/v2/types/page"
				}
			],
			"collection": [
				{
					"href": "https://demo.wp-api.org/wp-json/wp/v2/search"
				}
			]
		}
	},
	...
	...
	...
]