jindan

Untitled

Jul 15th, 2013
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.09 KB | None | 0 0
  1. <? require_once('wp-config.php');
  2. /* for loop to get data */
  3. $string = file_get_contents("/home/zhou3594/multi/hwzhiyin.json");
  4. $json_str = json_decode($string, true);
  5.  
  6.  
  7. $i = 0;
  8.  
  9. foreach($json_str as $row){
  10.     ++$i;
  11.     $urls = $row['urls'];
  12.     $mp3 = implode(',', $urls['mp3']);
  13.     $youtube = implode(',', $urls['youtube']);
  14.     $images = implode(',', $urls['images']);
  15.  
  16.     $my_post = array(
  17.         'post_title' => wp_strip_all_tags($row['title'][0]),
  18.         'post_content' => $row['content'],
  19.         'post_date' => $row['pdate'],
  20.         'post_name' => $row['alias'][0],
  21.         'post_status' => 'publish',
  22.         'post_author' => 1,
  23.         'post_category' => array(2, 6),
  24.     );
  25.     $post_id = wp_insert_post($my_post);
  26.     add_post_meta($post_id, 'created_by_alias', $row['poster'][0], true);
  27.     add_post_meta($post_id, 'post_url', $row['post_url'][0], true);
  28.     add_post_meta($post_id, 'mp3', $mp3, true);
  29.     add_post_meta($post_id, 'youtube', $youtube, true);
  30.     wp_set_post_terms($post_id, $tags_list);
  31.     echo 'Record ' . $i . ' processed';
  32.     echo "\r\n";
  33. }
Advertisement
Add Comment
Please, Sign In to add comment