# register_post_type()

URL: https://chugunov.pro/api-wordpress/functions/register_post_type/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 4.7.0.

## Сигнатура

```php
register_post_type( string $post_type, array|string $args = array() ): WP_Post_Type|WP_Error
```

## Описание

Примечание: регистрацию типов записей не следует подключать до действия ‘init’. Кроме того, любые связи с таксономиями следует регистрировать через аргумент $taxonomies, чтобы обеспечить согласованность при использовании таких хуков, как ‘parse_query’ или ‘pre_get_posts’.
Типы записей могут поддерживать любое количество встроенных возможностей ядра, таких как метабоксы, произвольные поля, миниатюры записей, статусы записей, комментарии и другое. Полный список поддерживаемых возможностей см. в аргументе $supports.

## Параметры

- `$post_type` `string` — обязательный. Ключ типа записи. Не должен превышать 20 символов и может содержать только строчные буквенно-цифровые символы, дефисы и подчёркивания. См. sanitize_key() .

## Возвращаемое значение

`WP_Post_Type|WP_Error` — WP_Error

## Исходный код

Файл: `wp-includes/post.php:1818`

```php
function register_post_type( $post_type, $args = array() ) {
	global $wp_post_types;

	if ( ! is_array( $wp_post_types ) ) {
		$wp_post_types = array();
	}

	// Sanitize post type name.
	$post_type = sanitize_key( $post_type );

	if ( empty( $post_type ) || strlen( $post_type ) > 20 ) {
		_doing_it_wrong( __FUNCTION__, __( 'Post type names must be between 1 and 20 characters in length.' ), '4.2.0' );
		return new WP_Error( 'post_type_length_invalid', __( 'Post type names must be between 1 and 20 characters in length.' ) );
	}

	$post_type_object = new WP_Post_Type( $post_type, $args );
	$post_type_object->add_supports();
	$post_type_object->add_rewrite_rules();
	$post_type_object->register_meta_boxes();

	$wp_post_types[ $post_type ] = $post_type_object;

	$post_type_object->add_hooks();
	$post_type_object->register_taxonomies();

	/**
	 * Fires after a post type is registered.
	 *
	 * @since 3.3.0
	 * @since 4.6.0 Converted the `$post_type` parameter to accept a WP_Post_Type object.
	 *
	 * @param string       $post_type        Post type.
	 * @param WP_Post_Type $post_type_object Arguments used to register the post type.
	 */
	do_action( 'registered_post_type', $post_type, $post_type_object );

	/**
	 * Fires after a specific post type is registered.
	 *
	 * The dynamic portion of the filter name, `$post_type`, refers to the post type key.
	 *
	 * Possible hook names include:
	 *
	 *  - `registered_post_type_post`
	 *  - `registered_post_type_page`
	 *
	 * @since 6.0.0
	 *
	 * @param string       $post_type        Post type.
	 * @param WP_Post_Type $post_type_object Arguments used to register the post type.
	 */
	do_action( "registered_post_type_{$post_type}", $post_type, $post_type_object );

	return $post_type_object;
}
```

## История изменений

- 5.9.0 — The rest_namespace argument was added.
- 5.3.0 — The supports argument will now accept an array of arguments for a feature.
- 5.0.0 — The template and template_lock arguments were added.
- 4.7.0 — Introduced show_in_rest, rest_base and rest_controller_class arguments to register the post type in REST API.
- 4.6.0 — Post type object returned is now an instance of WP_Post_Type.
- 4.4.0 — The show_ui argument is now enforced on the post type listing screen and post editing screen.
- 3.0.0 — The show_ui argument is now enforced on the new post screen.
- 2.9.0 — Introduced.

## Связанные

Использует: `WP_Post_Type::__construct`, [`__`](https://chugunov.pro/api-wordpress/functions/__/), [`sanitize_key`](https://chugunov.pro/api-wordpress/functions/sanitize_key/), [`_doing_it_wrong`](https://chugunov.pro/api-wordpress/functions/_doing_it_wrong/), [`do_action`](https://chugunov.pro/api-wordpress/functions/do_action/), `WP_Error::__construct`.
Используется в: [`create_initial_post_types`](https://chugunov.pro/api-wordpress/functions/create_initial_post_types/).

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/register_post_type/
