Title: get_default_post_to_edit
Published: April 25, 2014
Last modified: May 20, 2026

---

# get_default_post_to_edit( string $post_type = 'post', bool $create_in_db = false ): 󠀁[WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)󠁿

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/get_default_post_to_edit/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/get_default_post_to_edit/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/get_default_post_to_edit/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/get_default_post_to_edit/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/get_default_post_to_edit/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_default_post_to_edit/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/get_default_post_to_edit/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/get_default_post_to_edit/?output_format=md#wp--skip-link--target)

Returns default post information to use when populating the “Write Post” form.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/get_default_post_to_edit/?output_format=md#parameters)󠁿

 `$post_type`stringoptional

A post type string. Default `'post'`.

Default:`'post'`

`$create_in_db`booloptional

Whether to insert the post into database.

Default:`false`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_default_post_to_edit/?output_format=md#return)󠁿

 [WP_Post](https://developer.wordpress.org/reference/classes/wp_post/) Post object
containing all the default post data as attributes

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_default_post_to_edit/?output_format=md#source)󠁿

    ```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;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/post.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-admin/includes/post.php#L744)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-admin/includes/post.php#L744-L840)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/get_default_post_to_edit/?output_format=md#hooks)󠁿

 [apply_filters( ‘default_content’, string $post_content, WP_Post $post )](https://developer.wordpress.org/reference/hooks/default_content/)

Filters the default post content initially used in the “Write Post” form.

 [apply_filters( ‘default_excerpt’, string $post_excerpt, WP_Post $post )](https://developer.wordpress.org/reference/hooks/default_excerpt/)

Filters the default post excerpt initially used in the “Write Post” form.

 [apply_filters( ‘default_title’, string $post_title, WP_Post $post )](https://developer.wordpress.org/reference/hooks/default_title/)

Filters the default post title initially used in the “Write Post” form.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_default_post_to_edit/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_after_insert_post()](https://developer.wordpress.org/reference/functions/wp_after_insert_post/)`wp-includes/post.php` |

Fires actions after a post, its terms and meta data has been saved.

  | 
| [get_default_comment_status()](https://developer.wordpress.org/reference/functions/get_default_comment_status/)`wp-includes/comment.php` |

Gets the default comment status for a post type.

  | 
| [wp_next_scheduled()](https://developer.wordpress.org/reference/functions/wp_next_scheduled/)`wp-includes/cron.php` |

Retrieves the timestamp of the next scheduled event for the given hook.

  | 
| [wp_schedule_event()](https://developer.wordpress.org/reference/functions/wp_schedule_event/)`wp-includes/cron.php` |

Schedules a recurring event.

  | 
| [WP_Post::__construct()](https://developer.wordpress.org/reference/classes/wp_post/__construct/)`wp-includes/class-wp-post.php` |

Constructor.

  | 
| [wp_insert_post()](https://developer.wordpress.org/reference/functions/wp_insert_post/)`wp-includes/post.php` |

Inserts or updates a post in the database.

  | 
| [post_type_supports()](https://developer.wordpress.org/reference/functions/post_type_supports/)`wp-includes/post.php` |

Checks a post type’s support for a given feature.

  | 
| [set_post_format()](https://developer.wordpress.org/reference/functions/set_post_format/)`wp-includes/post-formats.php` |

Assign a format to a post

  | 
| [current_theme_supports()](https://developer.wordpress.org/reference/functions/current_theme_supports/)`wp-includes/theme.php` |

Checks a theme’s support for a given feature.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  | 
| [wp_unslash()](https://developer.wordpress.org/reference/functions/wp_unslash/)`wp-includes/formatting.php` |

Removes slashes from a string or recursively removes slashes from strings within an array.

  | 
| [esc_html()](https://developer.wordpress.org/reference/functions/esc_html/)`wp-includes/formatting.php` |

Escaping for HTML blocks.

  | 
| [wp_die()](https://developer.wordpress.org/reference/functions/wp_die/)`wp-includes/functions.php` |

Kills WordPress execution and displays HTML page with an error message.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  | 
| [get_option()](https://developer.wordpress.org/reference/functions/get_option/)`wp-includes/option.php` |

Retrieves an option value based on an option name.

  | 
| [get_post()](https://developer.wordpress.org/reference/functions/get_post/)`wp-includes/post.php` |

Retrieves post data given a post ID or post object.

  | 
| [is_wp_error()](https://developer.wordpress.org/reference/functions/is_wp_error/)`wp-includes/load.php` |

Checks whether the given variable is a WordPress Error.

  |

[Show 12 more](https://developer.wordpress.org/reference/functions/get_default_post_to_edit/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/get_default_post_to_edit/?output_format=md#)

| Used by | Description | 
| [get_default_page_to_edit()](https://developer.wordpress.org/reference/functions/get_default_page_to_edit/)`wp-admin/includes/deprecated.php` |

Gets the default page information to use.

  | 
| [wp_dashboard_quick_press()](https://developer.wordpress.org/reference/functions/wp_dashboard_quick_press/)`wp-admin/includes/dashboard.php` |

Displays the Quick Draft widget.

  | 
| [WP_Posts_List_Table::inline_edit()](https://developer.wordpress.org/reference/classes/wp_posts_list_table/inline_edit/)`wp-admin/includes/class-wp-posts-list-table.php` |

Outputs the hidden row displayed when inline editing

  | 
| [wp_xmlrpc_server::mw_newPost()](https://developer.wordpress.org/reference/classes/wp_xmlrpc_server/mw_newpost/)`wp-includes/class-wp-xmlrpc-server.php` |

Creates a new post.

  | 
| [wp_xmlrpc_server::_insert_post()](https://developer.wordpress.org/reference/classes/wp_xmlrpc_server/_insert_post/)`wp-includes/class-wp-xmlrpc-server.php` |

Helper method for wp_newPost() and wp_editPost(), containing shared logic.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_default_post_to_edit/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.0.0](https://developer.wordpress.org/reference/since/2.0.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/get_default_post_to_edit/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/functions/get_default_post_to_edit/?output_format=md#comment-content-4491)
 2.   [Codex](https://profiles.wordpress.org/codex/)  [  6 years ago  ](https://developer.wordpress.org/reference/functions/get_default_post_to_edit/#comment-4491)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_default_post_to_edit%2F%23comment-4491)
    Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_default_post_to_edit%2F%23comment-4491)
 4. Before using this function for your own theme or plugin, be wary of these non-obvious
    implicit behaviors (as of 4.2.3):
 5.  * The returned post will have a `post_category` member set, even if the `$post_type`
       does not use the category taxonomy.
     * This `post_category` value will be scalar, which causes warnings passed into`
       wp_insert_post` without additional manipulation.
     * Some of the post’s fields will be pulled out of `$_REQUEST` if present, which
       may not be the intended goal.
 6.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_default_post_to_edit%2F%3Freplytocom%3D4491%23feedback-editor-4491)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_default_post_to_edit%2F)
before being able to contribute a note or feedback.