Support » Fixing WordPress » Curl/Json doesnt work on wordpress

  • <?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);
                 return $result;
            // Pulls and parses data.
            $result = fetchData("$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?

Viewing 1 replies (of 1 total)
  • Try to change

    $result = fetchData("$userid/media/recent/?access_token=$accessToken");

    to this:

    $result = file_get_contents("$userid/media/recent/?access_token=$accessToken");

    and this
    <?php foreach ($result->data as $post): ?>

    to this:

    <?php foreach ((array) $result->data as $post): ?>

    This solution worked for me.

Viewing 1 replies (of 1 total)
  • The topic ‘Curl/Json doesnt work on wordpress’ is closed to new replies.