wp_insert_post( array $postarr, bool $wp_error = false )

Insert or update a post.


25 related functions found for: wp_insert_post

Top ↑

Related terms found for this post

TaxonomyTerms
wp-parser-related-wordsinsert, post, post-php, post-typ, post-type, wp-includes, wp-insert
wp-parser-packagePost, WordPress
wp-parser-source-filewp-includes/post.php

Top ↑

Terms Used Terms Used

Terms used in the related posts query

  • insert
  • post
  • Post
  • post-php
  • post-typ
  • post-type
  • wp-includes
  • wp-includes/post.php
  • wp-insert

Top ↑

Description Description

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.


Top ↑

Parameters Parameters

$postarr

(array) (Required) An array of elements that make up a post to update or insert.

  • 'ID'
    (int) The post ID. If equal to something other than 0, the post with that ID will be updated. Default 0.
  • 'post_author'
    (int) The ID of the user who added the post. Default is the current user ID.
  • 'post_date'
    (string) The date of the post. Default is the current time.
  • 'post_date_gmt'
    (string) The date of the post in the GMT timezone. Default is the value of $post_date.
  • 'post_content'
    (mixed) The post content. Default empty.
  • 'post_content_filtered'
    (string) The filtered post content. Default empty.
  • 'post_title'
    (string) The post title. Default empty.
  • 'post_excerpt'
    (string) The post excerpt. Default empty.
  • 'post_status'
    (string) The post status. Default 'draft'.
  • 'post_type'
    (string) The post type. Default 'post'.
  • 'comment_status'
    (string) Whether the post can accept comments. Accepts 'open' or 'closed'. Default is the value of 'default_comment_status' option.
  • 'ping_status'
    (string) Whether the post can accept pings. Accepts 'open' or 'closed'. Default is the value of 'default_ping_status' option.
  • 'post_password'
    (string) The password to access the post. Default empty.
  • 'post_name'
    (string) The post name. Default is the sanitized post title when creating a new post.
  • 'to_ping'
    (string) Space or carriage return-separated list of URLs to ping. Default empty.
  • 'pinged'
    (string) Space or carriage return-separated list of URLs that have been pinged. Default empty.
  • 'post_modified'
    (string) The date when the post was last modified. Default is the current time.
  • 'post_modified_gmt'
    (string) The date when the post was last modified in the GMT timezone. Default is the current time.
  • 'post_parent'
    (int) Set this for the post it belongs to, if any. Default 0.
  • 'menu_order'
    (int) The order the post should be displayed in. Default 0.
  • 'post_mime_type'
    (string) The mime type of the post. Default empty.
  • 'guid'
    (string) Global Unique ID for referencing the post. Default empty.
  • 'post_category'
    (array) Array of category names, slugs, or IDs. Defaults to value of the 'default_category' option.
  • 'tax_input'
    (array) Array of taxonomy terms keyed by their taxonomy name. Default empty.
  • 'meta_input'
    (array) Array of post meta values keyed by their post meta key. Default empty.

$wp_error

(bool) (Optional) Whether to return a WP_Error on failure.

Default value: false


Top ↑

Return Return

(int|WP_Error) The post ID on success. The value 0 or WP_Error on failure.


Top ↑

Source Source

File: wp-includes/post.php


			

Top ↑

Changelog Changelog

Changelog
Version Description
4.4.0 A 'meta_input' array can now be passed to $postarr to add post meta data.
4.2.0 Support was added for encoding emoji in the post title, content, and excerpt.
1.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.