wp_insert_post ( $postarr, $wp_error = false )

  • (array) $postarr { An array of elements that make up a post to update or insert.
  • (bool) $wp_error Optional. Whether to return a WP_Error on failure. Default false.
  • (int|WP_Error) The post ID on success. The value 0 or WP_Error on failure.
Defined at:
Change Log:
  • 4: .
  • 4: .


Insert or update a post.

If the $postarr parameter has 'ID' set to a value, then post will be updated.

You can set the post date manually, by setting the values for 'post_date' and 'post_date_gmt' keys. You can close the comments or open the comments by setting the value for 'comment_status' key.

Related Functions

wp_insert_site, wp_insert_term, wp_insert_user, wp_insert_comment, wp_kses_post

Top Google Results

User discussions

wpseek mobile