Title: write_post
Published: April 25, 2014
Last modified: February 24, 2026

---

# write_post(): int|void

## In this article

 * [Return](https://developer.wordpress.org/reference/functions/write_post/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/write_post/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/write_post/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/write_post/?output_format=md#changelog)

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

Calls [wp_write_post()](https://developer.wordpress.org/reference/functions/wp_write_post/)
and handles the errors.

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

 int|void Post ID on success, void on failure.

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

    ```php
    function write_post() {
    	$result = wp_write_post();
    	if ( is_wp_error( $result ) ) {
    		wp_die( $result->get_error_message() );
    	} else {
    		return $result;
    	}
    }
    ```

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

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

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

Creates a new post from the “Write Post” form using `$_POST` information.

  | 
| [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.

  | 
| [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 1 more](https://developer.wordpress.org/reference/functions/write_post/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/write_post/?output_format=md#)

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

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

## User Contributed Notes

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