• This is basically the same question as a previous forum post. I’m using wp_insert_post() to create drafts. For drafts, the post_modified field is set to the current date, but the post_modified_gmt field is set to ‘0000-00-00 00:00:00’. From the code in /wp-includes/post.php, it looks intentional:

    if ( empty( $postarr['post_date_gmt'] ) || '0000-00-00 00:00:00' == $postarr['post_date_gmt'] ) {
        if ( ! in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) {
            $post_date_gmt = get_gmt_from_date( $post_date );
        } else {
            $post_date_gmt = '0000-00-00 00:00:00';
        }
    

    I was tempted to file a bug report, but I thought I’d check to see if someone could explain the reason for not setting post_modified_gmt if post_modified is going to be set.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    Thread Starter jonesb

    (@jonesb)

    Thanks, but I think that refers to code that is called after $post_date_gmt has already been set to ‘0000-00-00 00:00:00’. In WP 4.9.7, it looks like the code in that ticket occurs on line 3282. The code I’m referring to occurs on line 3272.

    This is my first time looking at WordPress core code, and I don’t have that much experience with PHP, so I might be mistaken, but it looks like the following happens when calling wp_insert_post() with an ID of zero and no value for post_date and post_date_gmt (line numbers are from /wp-includes/post.php):
    1. $post_date is set to current_time(‘mysql’) on line 3251
    2. for a draft, $post_date_gmt is set to ‘0000-00-00 00:00:00’ on line 3276
    2a. for a published post, $post_date_gmt is set to get_gmt_from_date($post_date)
    3. $post_modified is set to $post_date on line 3286
    4. $post_modified_gmt is set to $post_date_gmt on line 3287
    5. $post_modified and $post_modified_gmt are passed through to the database at some later point.

    The issue I’m wondering about is in parts 2 and 2a above. Why is only the post_modified field set to the current date while the post_modified_gmt field is not?

    I hope that’s clear, and not too much information. And thanks again for your quick response.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Setting post_date_gmt on drafts’ is closed to new replies.