Title: Make curl/json work on wordpress
Last modified: August 21, 2016

---

# Make curl/json work on wordpress

 *  [halluzineyt](https://wordpress.org/support/users/halluzineyt/)
 * (@halluzineyt)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/make-curljson-work-on-wordpress/)
 *     ```
       <?php
   
         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=60");
   
         $result = json_decode($result);
         foreach ($result->data as $post) {
            if(empty($post->caption->text)) {
              // Do Nothing
            }
            else {
               echo '<a class="instagram-unit" target="blank" href="'.$post->link.'">
               <img src="'.$post->images->low_resolution->url.'" alt="'.$post->caption->text.'" width="50" height="auto" />
               </a>';
            }
   
         }
       ?>
       ```
   
 * I got this bit of code to pull instagram images, it works on some online compiler
   but i cant make it work on wordpress any idea how?

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Josh](https://wordpress.org/support/users/josh401/)
 * (@josh401)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/make-curljson-work-on-wordpress/#post-4855745)
 * I am not too familiar with cURL.. but I think the [HTTP API](http://codex.wordpress.org/HTTP_API)
   from the Codex is more of what you want to do.
 *  Thread Starter [halluzineyt](https://wordpress.org/support/users/halluzineyt/)
 * (@halluzineyt)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/make-curljson-work-on-wordpress/#post-4855777)
 *     ```
       <?php
   
       $result = wp_remote_get( "https://api.instagram.com/v1/users/***********/media/recent/?access_token=**********6" );
   
         $result = json_decode($result);
         foreach ($result->data as $post) {
            if(empty($post->caption->text)) {
              // Do Nothing
            }
            else {
               echo '<a class="instagram-unit" target="blank" href="'.$post->link.'">
               <img src="'.$post->images->low_resolution->url.'" alt="'.$post->caption->text.'" width="50" height="auto" />
               </a>';
            }
   
         }
       ?>
       ```
   
 * i tried this still doesnt work/
 *  Thread Starter [halluzineyt](https://wordpress.org/support/users/halluzineyt/)
 * (@halluzineyt)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/make-curljson-work-on-wordpress/#post-4855805)
 *     ```
       <?php
   
         $result = wp_remote_get("https://api.instagram.com/v1/users/*********/media/recent/?access_token=*********&count=60", true);
       	$decode = json_decode($result['body'], true);
   
         foreach ($decode->data as $post) {
            if(empty($post->caption->text)) {
              // Do Nothing
            }
            else {
               echo '<a class="instagram-unit" target="blank" href="'.$post->link.'">
               <img src="'.$post->images->low_resolution->url.'" alt="'.$post->caption->text.'" width="50" height="auto" />
               </a>';
            }
   
         }
       ?>
       ```
   
 * Can you check this one?

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Make curl/json work on wordpress’ is closed to new replies.

## Tags

 * [curl](https://wordpress.org/support/topic-tag/curl/)
 * [json](https://wordpress.org/support/topic-tag/json/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [halluzineyt](https://wordpress.org/support/users/halluzineyt/)
 * Last activity: [12 years, 1 month ago](https://wordpress.org/support/topic/make-curljson-work-on-wordpress/#post-4855805)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
