Codex

Function Reference/wp update post

Contents

Description

This function updates posts (and pages) in the database. To work as expected, it is necessary to pass the ID of the post to be updated.

Usage

 <?php wp_update_post$post ); ?> 

Example

Before calling wp_update_post() it is necessary to create an array to pass the necessary elements. Unlike wp_insert_post(), it is only necessary to pass the ID of the post to be updated and the elements to be updated. The names of the elements should match those in the database.

// Update post 37
  $my_post = array();
  $my_post['ID'] = 37;
  $my_post['post_content'] = 'This is the updated content.';

// Update the post into the database
  wp_update_post( $my_post );

Categories

Categories need to be passed as an array of integers that match the category IDs in the database. This is the case even where only one category is assigned to the post.

Parameters

$post
(array) (optional) An object representing the elements that make up a post. There is a one-to-one relationship between these elements and the names of columns in the wp_posts table in the database. Filling out the ID field is not strictly necessary but without it there is little point to using the function.
Default: An empty array

Return

The ID of the post if the post is successfully added to the database. Otherwise returns 0.

Related

wp_insert_post()

This article is marked as in need of editing. You can help Codex by editing it.