I am importing blog content that I have extracted in json format. I am having trouble getting the date to import because it is currently in strtotime() format. I need to reverse this when importing in order to import the date correctly. Any suggestions or help will be appreciated.
PHP
<?php
$json_feed = "http://localhost/sample/json/sample.json";
$json = file_get_contents($json_feed);
$obj = json_decode($json, true);
$date = date('Y/m/d H:i:s', strtotime($obj['post'].dateToPublish));
foreach($obj['post'] as $article_array){
$url = $article_array['url'];
$title = $article_array['title'];
$category = $article_array['category'];
$large_summary = $article_array['wp_post_content'];
$date = $article_array['dateToPublish'];
$post = array(
'post_title' => $title,
'post_content' => $large_summary,
'post_status' => 'publish',
'post_type' => 'post',
'comment_status' => 'closed',
'date' => $date,
'post_template' => 'content.php'
);
wp_insert_post ($post, $wp_error);
}
?>
JSON data:
"post": [
{
"updatedByUser": "Author-Name",
"author": "Author-Name",
"dateToPublish": 1418869808504,
"nid": 2413,
"contentId": "54923c30202946517983d30d",
"type": "post",
"title": "This is a post title!",
"wp_post_content": "This is post content!",
"not_type": "post",
"datePublished": 1418869808504,
"dateCreated": 1263356908,
"appLength": 0,
"idOLD": "54923c30202946517983d30d",
"slug": "This-is-a-slug",
"createByUser": "Author-Name"
},
{
"updatedByUser": "Author-Name",
"author": "Author-Name",
"dateToPublish": 1418869808508,
"nid": 2420,
"contentId": "54923c30202946517983d314",
"type": "post",
"title": "This is a title!",
"wp_post_content": "This is post content!",
"not_type": "post",
"datePublished": 1418869808508,
"dateCreated": 1265775472,
"appLength": 0,
"idOLD": "54923c30202946517983d314",
"slug": "This-is-a-slug",
"createByUser": "Author-Name"
}
]