Opens in a new tab
A picture of Jeff Brigman
I CODE TODAY FOR
A BETTER TOMORROW

Glossary Term

wp_insert_post()

3 tags 1 category

wp_insert_post() — Inserts or updates a post in the database. If the $postarr parameter contains an ‘ID’, the corresponding post will be updated. If not, a new post will be created using the values provided. 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.

Inputs: $postarr (array): An array of elements that make up a post to update or insert. Field $ID (int): The post ID. If equal to something other than 0, the post with that ID will be updated. Default 0. Field $post_author (int): The ID of the user who added the post. Default is the current user ID. Field $post_date (string): The date of the post. Default is the current time. Field $post_date_gmt (string): The date of the post in the GMT timezone. Default is the value of $post_date. Field $post_content (string): The post content. Default empty. Field $post_content_filtered (string): The filtered post content. Default empty. Field $post_title (string): The post title. Default empty. $wp_error (bool): Optional. Whether to return a WP_Error on failure. Default false. $fire_after_hooks (bool): Optional. Whether to fire the after insert hooks. Default true.

Returns int|WP_Error: The post ID on success. The value 0 or WP_Error on failure.

Term Connections

Explore related terms connected by shared tags, shared categories, and relationship phrases. This map loads only when it comes into view.

Loading term connections…