I'm inserting information from a user into a custom post type. $current_user it a user-object.

Is there anything special I have to think of when setting post_date_gmt when inserting a new post with wp_insert_post? (Or could I just fetch the value from the user-table like below?

$pupil = array(
              'post_title'      => $current_user->display_name,
              'post_date'       => $current_user->user_registered,
              'post_date_gmt'   => $current_user->user_registered,
              'post_type'       => 'pupil',
              'post_status'     => 'private',                     //This registration cpt is not available for public
              'post_author'     => $current_user->ID
            $postid_pupil = wp_insert_post( $pupil )

Most of the times, you can just leave it empty and the wp_insert_post will take care of handling it but if you want to set it use php's function:

gmdate("Y-m-d h:m:s", strtotime($current_user->user_registered))

which works exactly like the php date function.

  • 1
    gmdate("Y-m-d h:i:s", strtotime($current_user->user_registered)) – Rajeev Vyas Feb 20 '14 at 11:11


As the name suggest it is date time in GMT. GMT(Greenwich Mean Time) is a timezone.

wp_insert_post internally converts post_date into GMT using get_gmt_from_date . So if you don't pass it, it will do it for you.

Or you can use


to convert your date to GMT.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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