「関数リファレンス/wp update post」の版間の差分
(en:Function Reference/wp update post 05:40, 31 March 2010 Bennebw)
2010年5月2日 (日) 21:51時点における版
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.
Note that when the post is "updated", the existing Post record is duplicated for audit/revision purposes. The primary record is then updated with the new values. Category associations, custom fields, post meta, and other related entries continue to be linked to the primary Post record.
%%% <?php wp_update_post( $post ); ?> %%%
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 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.
- （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.
- 初期値： An empty array
The ID of the post if the post is successfully added to the database. Otherwise returns 0.