Skip to content

Instantly share code, notes, and snippets.

@coryetzkorn
Created May 1, 2015 19:02
Show Gist options
  • Save coryetzkorn/0223245750fa12149d10 to your computer and use it in GitHub Desktop.
Save coryetzkorn/0223245750fa12149d10 to your computer and use it in GitHub Desktop.
JSON to Wordpress Import
$json = file_get_contents(get_bloginfo('template_directory') . '/posts.json');
$json = json_decode($json);
foreach($json as $post) {
$my_post = array(
'post_title' => $post->title,
'post_date' => date("Y-m-d", strtotime($post->date)),
'post_status' => 'publish',
'post_type' => 'press',
'post_author' => 1
);
$new_post_id = wp_insert_post($my_post);
add_post_meta($new_post_id, 'source', $post->source, true);
add_post_meta($new_post_id, 'url', $post->url, true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment