I am trying to create this plugin for my site that will allow create short codes to pull data from the iTunes Search SDK. I already have the iTunes Search SDK javascript plugin working that pulls the data from the search SDK but I am running into an issue with placing the required javascript into the shortcode.
The code I have looks like this:
<?php
add_action('init', 'peb_init');
function peb_init() {
add_action('admin_head', 'peb_admin_head');
}
function peb_admin_head() {
echo '<script type="text/javascript">';
require_once('https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.js');
require_once('js.php');
echo '</script>';
}
add_filter('widget_text', 'do_shortcode');
add_shortcode('appPrice', 'appPrice');
function appPrice($atts)
{
$atts = shortcode_atts(
array(
'id' => '',
'class' => '',
'container' => ''
), $atts);
return '
<script type="text/javascript">
$(document).ready(function() {
var url = 'iLookup.php';
query = $id;
$.getJSON(url, {id:query}, function(json) {
$('#results').html('Price: '+json.results[0].price+'<br/>');
});
});
</script>
';
}
If anyone has any ideas as to why this doesn't work I would be very appreciative. If there is not enough info given I will be glad to provide more.
NOTE: There is no error message it just doesn't work. I have tried using the console log and it still doesn't work. The rest of the plugin works fine with the exception of the script.