I’ve got this working to pull recent Instagram posts into WordPress, however the “recent” photos that are displayed aren’t actually my most recent Instagram posts. When I refresh, the Instagram posts that are pulled in also change. I can only find a max/min time within the API docs. Is there any way to just get the last 3 Instagram posts made?
<?php
$json = file_get_contents('https://api.instagram.com/v1/users/user-id/media/recent/?access_token=key-number');
$a_json = json_decode($json, true);
foreach( $a_json['data'] as $key => $value) {
$a_images[$value['id']]['link'] = $value['link'];
$a_images[$value['id']]['url'] = $value['images']['standard_resolution']['url'];
$a_images[$value['id']]['caption'] = $value['caption']['text'];
}
shuffle($a_images);
echo '<ul>';
$i = 0;
foreach($a_images as $image) {
if ($i < 3) {
echo '<li class="large-4 columns">
<div class="front">
<a href="'.$image[link].'" target="_blank">
<img src="'.$image[url].'"/>
</a>
</div>
<div class="back">
<p>'.$image.'</p>
</div>
</li>';
$i++;
}
}
echo '</ul>';
You are receiving the data in the right order, but then you are using the
shuffle()
function on the images array$a_images
you created .if you remove the
shuffle($a_images);
from your code it’ll be just fine.and replace
$image[link]
,$image[url]
and$image[caption]
with$image['link']
,$image['url']
and$image['caption']
sorry for bad english