Import JSON feed to Wordpress

We have received a URL which is a JSON file apparently:?destination=hawaiiI am completely clueless when it comes to JSO

We have received a URL which is a JSON file apparently:

/?destination=hawaii

I am completely clueless when it comes to JSON and Wordpress.

Anybody know where to start?

We will need to create individual posts from this JSON file I presume..

We have received a URL which is a JSON file apparently:

http://www.domain/tools/export-json/?destination=hawaii

I am completely clueless when it comes to JSON and Wordpress.

Anybody know where to start?

We will need to create individual posts from this JSON file I presume..

Share Improve this question asked Jun 7, 2013 at 18:17 Mario LorenzoMario Lorenzo 791 gold badge4 silver badges8 bronze badges 1
  • There are some PHP native function like json_encode() and json_decode() – JMau Commented Jun 7, 2013 at 18:31
Add a comment  | 

1 Answer 1

Reset to default 11
  1. json_decode the JSON into an array.

    $slices = json_decode(file_get_contents('yourJSONFile.json'),true);
    
  2. Loop into the data

    if ($slices) { 
       foreach ($slices as $slice) {
          $title = $slice[1];
          // insert more logic here
      }
    } 
    
  3. Create a post programmatically by using wp_insert_post.

    // Create post object
    $my_post = array(
         'post_title'    =>  $title,
         'post_content'  => 'This is my content',
         'post_status'   => 'publish',
         'post_author'   => 1,
         'post_category' => array(8,39)
    );
    
    // Insert the post into the database and return the new post ID
    $post_id = wp_insert_post( $my_post, true );
    if ( is_wp_error( $post_id ) ) {
         // error handling....
    }
    

More details in this tutorial: http://tommcfarlin/programmatically-create-a-post-in-wordpress/

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745204942a4616548.html

相关推荐

  • Import JSON feed to Wordpress

    We have received a URL which is a JSON file apparently:?destination=hawaiiI am completely clueless when it comes to JSO

    7小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信