Skip to content

Instantly share code, notes, and snippets.

@aolin480
Created June 27, 2018 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aolin480/fb1b2baa6b3c96243ad269ba9ce576d6 to your computer and use it in GitHub Desktop.
Save aolin480/fb1b2baa6b3c96243ad269ba9ce576d6 to your computer and use it in GitHub Desktop.
Convert EPOCH timestamp to Wordpress post_date
<?php
$timestamp = '1517341140000';
$post_arr = [
'post_title' => 'Meh title',
'post_type' => 'post', //could be any custom post type
'post_content' => 'Meh body',
'post_category' => ['meh category'],
'post_status' => 'publish'
];
$post_arr['post_date'] = date("Y-m-d H:i:s", substr($timestamp, 0, 10));
// $post_id = wp_insert_post($post_arr);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment