Post Types (types)

These routes allow you to retrieve data for all or a specified type of record. It works with the data of the record type itself, not the entries of the specified type!

Possible routes (endpoints are described below):

/wp/v2/types              // works with all post types
/wp/v2/types/{post_type}  // works with the specified post type instead of {post_type}

Controller class: WP_REST_Post_Types_Controller{}

Resource Schema

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

Parameter Context Description
capabilities
object
edit All capabilities used by the record type.
Read-only.
description
string
view, edit Description of the record type.
Read-only.
hierarchical
true/false
view, edit Can this record type be a parent.
Read-only.
viewable
true/false
edit Can the record type be publicly viewable.
Read-only.
labels
object
edit Labels for the record type in various contexts.
Read-only.
name
string
view, edit, embed Name of the record type.
Read-only.
slug
string
view, edit, embed Slug of the record type.
Read-only.
supports
object
edit All capabilities supported by the record type.
Read-only.
taxonomies
array
view, edit Taxonomies associated with the record type.
Read-only.
rest_base
string
view, edit, embed REST base path for the record type.
Read-only.

Route Description

$ curl -X OPTIONS -i http://demo.wp-api.org/wp-json/wp/v2/types
GitHub
{
    "namespace": "wp/v2",
    "methods": [
        "GET"
    ],
    "endpoints": [
        {
            "methods": [
                "GET"
            ],
            "args": {
                "context": {
                    "required": false,
                    "default": "view",
                    "enum": [
                        "view",
                        "embed",
                        "edit"
                    ],
                    "description": "Рамки в которых сделан запрос, определяют поля в ответе.",
                    "type": "string"
                }
            }
        }
    ],
    "schema": {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "title": "type",
        "type": "object",
        "properties": {
            "capabilities": {
                "description": "Все возможности используемые типом записи.",
                "type": "object",
                "context": [
                    "edit"
                ],
                "readonly": true
            },
            "description": {
                "description": "Человекочитаемое описание типа записи.",
                "type": "string",
                "context": [
                    "view",
                    "edit"
                ],
                "readonly": true
            },
            "hierarchical": {
                "description": "Может ли этот тип записи быть родительским.",
                "type": "boolean",
                "context": [
                    "view",
                    "edit"
                ],
                "readonly": true
            },
            "viewable": {
                "description": "Может ли тип записи быть доступным для просмотра.",
                "type": "boolean",
                "context": [
                    "edit"
                ],
                "readonly": true
            },
            "labels": {
                "description": "Человекочитабельные метки для типа записи для различных контекстов.",
                "type": "object",
                "context": [
                    "edit"
                ],
                "readonly": true
            },
            "name": {
                "description": "Название для типа записи.",
                "type": "string",
                "context": [
                    "view",
                    "edit",
                    "embed"
                ],
                "readonly": true
            },
            "slug": {
                "description": "Буквенно-цифровой идентификатор типа записи.",
                "type": "string",
                "context": [
                    "view",
                    "edit",
                    "embed"
                ],
                "readonly": true
            },
            "supports": {
                "description": "Все возможности поддерживаемые типом записи.",
                "type": "object",
                "context": [
                    "edit"
                ],
                "readonly": true
            },
            "taxonomies": {
                "description": "Таксономии ассоциированные с типом записи.",
                "type": "array",
                "items": {
                    "type": "string"
                },
                "context": [
                    "view",
                    "edit"
                ],
                "readonly": true
            },
            "rest_base": {
                "description": "базовый путь REST для типа записи.",
                "type": "string",
                "context": [
                    "view",
                    "edit",
                    "embed"
                ],
                "readonly": true
            }
        }
    },
    "_links": {
        "self": "http://wptest.ru/wp-json/wp/v2/types"
    }
}
$ curl -X OPTIONS -i http://demo.wp-api.org/wp-json/wp/v2/types/{post_type}
GitHub
{
    "namespace": "wp/v2",
    "methods": [
        "GET"
    ],
    "endpoints": [
        {
            "methods": [
                "GET"
            ],
            "args": {
                "type": {
                    "required": false,
                    "description": "Буквенно-цифровой идентификатор типа записи.",
                    "type": "string"
                },
                "context": {
                    "required": false,
                    "default": "view",
                    "enum": [
                        "view",
                        "embed",
                        "edit"
                    ],
                    "description": "Рамки в которых сделан запрос, определяют поля в ответе.",
                    "type": "string"
                }
            }
        }
    ],
    "schema": {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "title": "type",
        "type": "object",
        "properties": {
            "capabilities": {
                "description": "Все возможности используемые типом записи.",
                "type": "object",
                "context": [
                    "edit"
                ],
                "readonly": true
            },
            "description": {
                "description": "Человекочитаемое описание типа записи.",
                "type": "string",
                "context": [
                    "view",
                    "edit"
                ],
                "readonly": true
            },
            "hierarchical": {
                "description": "Может ли этот тип записи быть родительским.",
                "type": "boolean",
                "context": [
                    "view",
                    "edit"
                ],
                "readonly": true
            },
            "viewable": {
                "description": "Может ли тип записи быть доступным для просмотра.",
                "type": "boolean",
                "context": [
                    "edit"
                ],
                "readonly": true
            },
            "labels": {
                "description": "Человекочитабельные метки для типа записи для различных контекстов.",
                "type": "object",
                "context": [
                    "edit"
                ],
                "readonly": true
            },
            "name": {
                "description": "Название для типа записи.",
                "type": "string",
                "context": [
                    "view",
                    "edit",
                    "embed"
                ],
                "readonly": true
            },
            "slug": {
                "description": "Буквенно-цифровой идентификатор типа записи.",
                "type": "string",
                "context": [
                    "view",
                    "edit",
                    "embed"
                ],
                "readonly": true
            },
            "supports": {
                "description": "Все возможности поддерживаемые типом записи.",
                "type": "object",
                "context": [
                    "edit"
                ],
                "readonly": true
            },
            "taxonomies": {
                "description": "Таксономии ассоциированные с типом записи.",
                "type": "array",
                "items": {
                    "type": "string"
                },
                "context": [
                    "view",
                    "edit"
                ],
                "readonly": true
            },
            "rest_base": {
                "description": "базовый путь REST для типа записи.",
                "type": "string",
                "context": [
                    "view",
                    "edit",
                    "embed"
                ],
                "readonly": true
            }
        }
    }
}

List of All Record Types

The algorithm is similar to the function get_post_types().

Request Type

Access: public

GET /wp/v2/types

Request Parameters

context(string)
The context in which the request is made; defines the fields present in the response.
Could be: view, embed, edit
Default: view

Example Request

$ curl http://demo.wp-api.org/wp-json/wp/v2/types

Response:

{
	"post": {
		"description": "",
		"hierarchical": false,
		"name": "Posts",
		"slug": "post",
		"taxonomies": [
			"category",
			"post_tag"
		],
		"rest_base": "posts",
		"_links": {
			"collection": [
				{
					"href": "http://example.com/wp-json/wp/v2/types"
				}
			],
			"wp:items": [
				{
					"href": "http://example.com/wp-json/wp/v2/posts"
				}
			],
			"curies": [
				{
					"name": "wp",
					"href": "https://api.w.org/{rel}",
					"templated": true
				}
			]
		}
	},
	"page": {
		"description": "",
		"hierarchical": true,
		"name": "Pages",
		"slug": "page",
		"taxonomies": [],
		"rest_base": "pages",
		"_links": {
			"collection": [
				{
					"href": "http://example.com/wp-json/wp/v2/types"
				}
			],
			"wp:items": [
				{
					"href": "http://example.com/wp-json/wp/v2/pages"
				}
			],
			"curies": [
				{
					"name": "wp",
					"href": "https://api.w.org/{rel}",
					"templated": true
				}
			]
		}
	},
	"attachment": {
		"description": "",
		"hierarchical": false,
		"name": "Media Files",
		"slug": "attachment",
		"taxonomies": [],
		"rest_base": "media",
		"_links": {
			"collection": [
				{
					"href": "http://example.com/wp-json/wp/v2/types"
				}
			],
			"wp:items": [
				{
					"href": "http://example.com/wp-json/wp/v2/media"
				}
			],
			"curies": [
				{
					"name": "wp",
					"href": "https://api.w.org/{rel}",
					"templated": true
				}
			]
		}
	}
}

Getting a Specified Record Type

Retrieves data for a specified record type.

Request Type

Access: public

GET /wp/v2/types/{post_type}

Request Parameters

type(string) (required)
Name of the record type whose data needs to be retrieved.
context(string)
The context in which the request is made; defines the fields present in the response.
Could be: view, embed, edit
Default: view

Example Request

$ curl http://demo.wp-api.org/wp-json/wp/v2/types/post

Response:

{
	"description": "",
	"hierarchical": false,
	"name": "Posts",
	"slug": "post",
	"taxonomies": [
		"category",
		"post_tag"
	],
	"rest_base": "posts",
	"_links": {
		"collection": [
			{
				"href": "http://example.com/wp-json/wp/v2/types"
			}
		],
		"wp:items": [
			{
				"href": "http://example.com/wp-json/wp/v2/posts"
			}
		],
		"curies": [
			{
				"name": "wp",
				"href": "https://api.w.org/{rel}",
				"templated": true
			}
		]
	}
}