# get_default_post_to_edit()

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

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

## Сигнатура

```php
get_default_post_to_edit( string $post_type = 'post', bool $create_in_db = false ): WP_Post
```

## Описание

Возвращает информацию о записи по умолчанию для заполнения формы «Написать запись».

## Параметры

- `$post_type` `string` — необязательный, по умолчанию `'post'`. Строка типа записи. По умолчанию 'post'.
- `$create_in_db` `bool` — необязательный, по умолчанию `false`. Вставлять ли запись в базу данных.

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

`WP_Post`

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

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

```php
function get_default_post_to_edit( $post_type = 'post', $create_in_db = false ) {
	$post_title = '';
	if ( ! empty( $_REQUEST['post_title'] ) ) {
		$post_title = esc_html( wp_unslash( $_REQUEST['post_title'] ) );
	}

	$post_content = '';
	if ( ! empty( $_REQUEST['content'] ) ) {
		$post_content = esc_html( wp_unslash( $_REQUEST['content'] ) );
	}

	$post_excerpt = '';
	if ( ! empty( $_REQUEST['excerpt'] ) ) {
		$post_excerpt = esc_html( wp_unslash( $_REQUEST['excerpt'] ) );
	}

	if ( $create_in_db ) {
		$post_id = wp_insert_post(
			array(
				'post_title'  => post_type_supports( $post_type, 'title' ) ? __( 'Auto Draft' ) : '',
				'post_type'   => $post_type,
				'post_status' => 'auto-draft',
			),
			true,
			false
		);

		if ( is_wp_error( $post_id ) ) {
			wp_die( $post_id->get_error_message() );
		}

		$post = get_post( $post_id );

		if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post->post_type, 'post-formats' ) && get_option( 'default_post_format' ) ) {
			set_post_format( $post, get_option( 'default_post_format' ) );
		}

		wp_after_insert_post( $post, false, null );

		// Schedule auto-draft cleanup.
		if ( ! wp_next_scheduled( 'wp_scheduled_auto_draft_delete' ) ) {
			wp_schedule_event( time(), 'daily', 'wp_scheduled_auto_draft_delete' );
		}
	} else {
		$post                 = new stdClass();
		$post->ID             = 0;
		$post->post_author    = '';
		$post->post_date      = '';
		$post->post_date_gmt  = '';
		$post->post_password  = '';
		$post->post_name      = '';
		$post->post_type      = $post_type;
		$post->post_status    = 'draft';
		$post->to_ping        = '';
		$post->pinged         = '';
		$post->comment_status = get_default_comment_status( $post_type );
		$post->ping_status    = get_default_comment_status( $post_type, 'pingback' );
		$post->post_pingback  = get_option( 'default_pingback_flag' );
		$post->post_category  = get_option( 'default_category' );
		$post->page_template  = 'default';
		$post->post_parent    = 0;
		$post->menu_order     = 0;
		$post                 = new WP_Post( $post );
	}

	/**
	 * Filters the default post content initially used in the "Write Post" form.
	 *
	 * @since 1.5.0
	 *
	 * @param string  $post_content Default post content.
	 * @param WP_Post $post         Post object.
	 */
	$post->post_content = (string) apply_filters( 'default_content', $post_content, $post );

	/**
	 * Filters the default post title initially used in the "Write Post" form.
	 *
	 * @since 1.5.0
	 *
	 * @param string  $post_title Default post title.
	 * @param WP_Post $post       Post object.
	 */
	$post->post_title = (string) apply_filters( 'default_title', $post_title, $post );

	/**
	 * Filters the default post excerpt initially used in the "Write Post" form.
	 *
	 * @since 1.5.0
	 *
	 * @param string  $post_excerpt Default post excerpt.
	 * @param WP_Post $post         Post object.
	 */
	$post->post_excerpt = (string) apply_filters( 'default_excerpt', $post_excerpt, $post );

	return $post;
}
```

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

- 2.0.0 — Introduced.

## Связанные

Использует: [`wp_after_insert_post`](https://chugunov.pro/api-wordpress/functions/wp_after_insert_post/), [`get_default_comment_status`](https://chugunov.pro/api-wordpress/functions/get_default_comment_status/), [`wp_next_scheduled`](https://chugunov.pro/api-wordpress/functions/wp_next_scheduled/), [`wp_schedule_event`](https://chugunov.pro/api-wordpress/functions/wp_schedule_event/), `WP_Post::__construct`, [`wp_insert_post`](https://chugunov.pro/api-wordpress/functions/wp_insert_post/), [`post_type_supports`](https://chugunov.pro/api-wordpress/functions/post_type_supports/), [`set_post_format`](https://chugunov.pro/api-wordpress/functions/set_post_format/), [`current_theme_supports`](https://chugunov.pro/api-wordpress/functions/current_theme_supports/), [`__`](https://chugunov.pro/api-wordpress/functions/__/), [`wp_unslash`](https://chugunov.pro/api-wordpress/functions/wp_unslash/), [`esc_html`](https://chugunov.pro/api-wordpress/functions/esc_html/), [`wp_die`](https://chugunov.pro/api-wordpress/functions/wp_die/), [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/), [`get_option`](https://chugunov.pro/api-wordpress/functions/get_option/), [`get_post`](https://chugunov.pro/api-wordpress/functions/get_post/), [`is_wp_error`](https://chugunov.pro/api-wordpress/functions/is_wp_error/).
Используется в: [`get_default_page_to_edit`](https://chugunov.pro/api-wordpress/functions/get_default_page_to_edit/), [`wp_dashboard_quick_press`](https://chugunov.pro/api-wordpress/functions/wp_dashboard_quick_press/), `WP_Posts_List_Table::inline_edit`, `wp_xmlrpc_server::mw_newPost`, `wp_xmlrpc_server::_insert_post`.

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