WordPress.org

Ready to get started?Download WordPress

Forums

Curl/Json doesnt work on wordpress (1 post)

  1. halluzineyt
    Member
    Posted 4 months ago #

    <?php
            // Supply a user id and an access token
            $userid = "****";
            $accessToken = "*****";
    
            // Gets our data
            function fetchData($url){
                 $ch = curl_init();
    			 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                 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;
            }
    
            // Pulls and parses data.
            $result = fetchData("https://api.instagram.com/v1/users/$userid/media/recent/?access_token=$accessToken");
            $result = json_decode($result);
        ?>
    
    <?php if(!empty($result->data)): ?>
        <?php foreach ($result->data as $post): ?>
            <!-- Renders images. @Options (thumbnail,low_resoulution, high_resolution) -->
            <a class="group" rel="group1" href="<?= $post->images->standard_resolution->url ?>"><img src="<?= $post->images->thumbnail->url ?>"></a>
        <?php endforeach ?>
    <?php endif ?>

    Im trying to add a separate php code to pull instagram photos to wordpress then integrate it with gridrotator.js. This code works on some online compiler but it doesnt seem to be working on wordpress do you know why?

Reply

You must log in to post.

About this Topic