Skip to content

Instantly share code, notes, and snippets.

@dcatkins40
Created January 22, 2013 16:23
Show Gist options
  • Select an option

  • Save dcatkins40/4596007 to your computer and use it in GitHub Desktop.

Select an option

Save dcatkins40/4596007 to your computer and use it in GitHub Desktop.
Example of using an PHP to access JSON if jQuery fails.
<?php
$response = wp_remote_get( '$API_URL' );
if( is_wp_error( $response ) ) {
echo 'Something went wrong!';
} else {
echo 'Response:<pre>';
print_r( $response );
echo '</pre>';
}
$decodedResponse = json_decode($response['body']);
$items = $decodedResponse->items;
<?php
foreach($items as $item) {
if($item->id == $videoID) { ?>
<img src="<?php echo $item->videoStillURL; ?>" />
<?php break;
}
} ?>
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment