2016-10-18 10 views
2

私は次のphpファイルを作成して、特定のユーザーの図表写真を取得しました。誰かが私のワードプレスサイトのメディアライブラリにこれらの写真を追加する方法について、正しい方向で私を指すことができますか?Instagramからメディアライブラリに画像を追加するwordpress

<?php 
/** 
* Template Name: Cronjob 
*/ 

    function fetchData($url){ 
     $ch = curl_init(); 
     curl_setopt($ch, CURLOPT_URL, $url); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
     curl_setopt($ch, CURLOPT_TIMEOUT, 20); 
     $result = curl_exec($ch); 
     curl_close($ch); 
     return $result; 
    } 

    $result = fetchData("https://api.instagram.com/v1/users/******/media/recent/?access_token=*************&count=5"); 
    $result = json_decode($result); 
    foreach ($result->data as $post) { 

    $new_post = wp_insert_post(array(
     'post_content' => '<a href="'. esc_url($post->link) .'" target="_blank"><img src="'. esc_url($post->images->standard_resolution->url) .'" alt="'. $post->caption->text .'" /></a>', 
     'post_name'  => $post->id, 
     'post_type' => 'instagram' 
    ), true); 
    } 
?> 

答えて

関連する問題