HTML,CSS,PHP,ワードプレスカスタマイズ 技術情報資料

WP データの更新

データの更新
※ソース1
$my_post = array();
$my_post['ID'] = ポストID;
$my_post['post_content'] = 'コンテンツ';

// データベース内の投稿を更新します。
  wp_update_post( $my_post );
post で使える連中は・・・
  'ID' => [ <投稿 ID> ] // 既存の投稿を更新する場合。
  'menu_order' => [ <順序値> ] // 追加する投稿が固定ページの場合、ページの並び順を番号で指定できます。
  'comment_status' => [ 'closed' | 'open' ] // 'closed' はコメントを閉じます。
  'ping_status' => [ 'closed' | 'open' ] // 'closed' はピンバック/トラックバックをオフにします。
  'pinged' => [ ? ] // ピンバック済。
  'post_author' => [ <user ID> ] // 作成者のユーザー ID。
  'post_category' => [ array(<カテゴリー ID>, <...>) ] // カテゴリーを追加。
  'post_content' => [ <投稿の本文> ] // 投稿の全文。
  'post_date' => [ Y-m-d H:i:s ] // 投稿の作成日時。
  'post_date_gmt' => [ Y-m-d H:i:s ] // 投稿の作成日時(GMT)。
  'post_excerpt' => [ <抜粋> ] // 投稿の抜粋。
  'post_name' => [ <スラッグ名> ] // 投稿スラッグ。
  'post_parent' => [ <投稿 ID> ] // 親投稿の ID。
  'post_password' => [ <投稿パスワード> ] // 投稿の閲覧時にパスワードが必要になります。
  'post_status' => [ 'draft' | 'publish' | 'pending'| 'future' ] // 公開ステータス。 
  'post_title' => [ <タイトル> ] // 投稿のタイトル。
  'post_type' => [ 'post' | 'page' ] // 投稿タイプ名。
  'tags_input' => [ '<タグ>, <タグ>, <...>' ] // 投稿タグ。
  'to_ping' => [ ? ] //?
カテゴリーがちょっと面倒
目的のカテゴリーを外すなら。
$post=get_post(ポストID);
$category_stk   =$post->post_category;
$categorynew_stk="";
foreach( $category_stk as $aaa ){
	if( 'いらないID'==$aaa ){
	}else{
		$categorynew_stk[]=$aaa;
	}
}
$post->post_category=$categorynew_stk;
wp_update_post($post);
※こういう処理が入らないのなら、ソース1のように変更したいフィールドだけ突っ込めばいい。

スポンサーリンク

関連記事

スポンサーリンク

カテゴリー