This may seem like a Wordpress problem but I think it's PHP specific rather than Wordpress. My problem is in the // Code
block I think. Here is my code:
function display_app_rating( $atts ) {
// Attributes
extract( shortcode_atts(
array(
'app' => '',
), $atts )
);
// Code
//return '"http://itunes.apple.com/lookup?id='.($app).'"';
$json_url = '"http://itunes.apple.com/lookup?id='.($app).'"';
$json = file_get_contents($json_url);
$result = json_decode($json, TRUE);
foreach ($result['results'] as $key => $value) {
return '<p class="appstore rating">Average rating '.$value['averageUserRating'].' out of 5 from '.$value['userRatingCount']. ' users.</p><p class="appstore price">Current Price '.$value['currency'].$value['price'].'</p>';
}
}
add_shortcode( 'apprating', 'display_app_rating' );
If I hardcode an app ID as the $app
variable it works fine and if I comment my code out and uncomment the return...
line it returns the correct URL. My question is how can I get the $app
variable appended to the URL and working via my shortcode which is
[apprating app="439438619"]
Any help appreciated.