web-dev-qa-db-ja.com

post_date_gmtとpost_date

Wp_insert_postを使用してプログラムで投稿を挿入しています。典型的な呼び出しは次のようになります。

$news_item = array (
    'post_title' => $titleField,
    'post_content' => $retrieve_result['content'],
    'post_status' => 'pending',
    'post_author' => $user->ID,
    'post_type' => 'post',
    'post_date_gmt' => $post_date_gmt
);

$post_id =  wp_insert_post( $news_item );

私の質問はパラメータpost_date_gmtについてです、これは正しい使い方ですか?代わりにpost_dateを使うべきですか?画面に表示される値は?両方の説明が必要です。ドキュメンテーションはあまり提供していません。

ありがとう。

2
Greeso

WP_Postwp-includes/post.phpクラスのコメントから:

'post_date'および 'post_date_gmt'キーの値を設定することで、投稿日を手動で設定できます。

プログラムで投稿を追加していて、日付を添付したい場合は、両方のキーを設定する必要があります。 (空白のままにした場合、WordPressは両方に適切な現在の日付を使用します。)

4
Pat J