2

I am inserting posts programmatically using wp_insert_post. A typical call would look like this:

$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 );

My question is about the parameter post_date_gmt, is this a correct use? Should I use post_date instead? What value is displayed on the screen? I need explanation of both. Documentation does not offer much.

Thanks.

4

From the comments in the WP_Post class in wp-includes/post.php:

You can set the post date manually, by setting the values for 'post_date' and 'post_date_gmt' keys.

So if you're adding a post programmatically, and you want a date attached, you should set both keys. (If you leave them blank, WordPress will use the appropriate current date for both.)

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.