wp_update_post

Sponsored Link

この関数はデータベースに投稿(とページ)を更新します。期待通りに動作するには、更新する投稿にIDを渡す必要があります。

投稿が”更新される”時、投稿レコードを存続するには監査/改正の目的のために複製されることに注意してください。プライマリーレコードは新しい値で更新されます。カテゴリーの関連付け、カスタムフィールド、投稿メタ、及びその他の関連エントリーは、プライマリー投稿レコードにリンクされ続けます。

Sponsored Link

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.

wp_update_postのファンクションタグ使用方法

<?php wp_update_post( $post ); ?> 

wp_update_post()を呼び出す前に、必要な要素を渡すための配列を作成剃る必要があります。wp_insert_post()とは異なり、更新される投稿IDと更新される要素を渡すためのみに必要です。要素の名前は、データベース内のそれらと一致させる必要があります。

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.

// 投稿37を更新します。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 );

カテゴリー

カテゴリーはデータベース内のカテゴリーIDを一致させる整数の配列として渡す必要があります。これは、1つのカテゴリーのみが投稿に割り当てられている場合の実例です。

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.

wp_update_postのパラメーター

$post

(array) (optional) 投稿を構成する要素を表すオブジェクトです。データベース内のwp_postsテーブルに列名とそれらの要素の間に1対1の関係があります。IDフィールド外に記入することは、必ずしも正確に関数を使用するための小さなポイントがある必要がありません。
デフォルト:空の配列

(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

戻り値

投稿のIDは投稿が正常にデータベースに追加されている場合、投稿のIDです。そうでなければ0を返します。

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

ソースファイル

wp_update_post()は、wp-includes/post.php内に位置しています。

wp_update_post() is located in wp-includes/post.php.

関連ファンクションタグ

wp_insert_post()

Sponsored Link