WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm working on incorporating the jPlayer into our WordPress site. I don't particularly care for the two plugins that are available as our client is a bit on the technically deficient side. What we are looking to accomplish is have the Title and Mp3 load into the JavaScript for the jPlayer playlist. Currently everything is loading just fine and returning the appropriate texts, however I'm unable to get the File Name and the Attachment URL to load appropriately. I'm fairly new to java and wordpress for that matter. Any help would be appreciated. If you would like to see a live site example, please visit http://www.ourgoodfight.com/?p=6054

<!--Begin Jplayer Playlist -->
<script type="text/javascript">
        new jPlayerPlaylist({
            jPlayer: "#jquery_jplayer_1",
            cssSelectorAncestor: "#jp_container_1"
        }, [
            global $post;
                $jukebox_args = get_posts( array(
                    'post_type' => 'attachment',
                    'posts_per_page' => -1,
                    'post_mime_type' => 'audio/mpeg',
                    'orderby' => 'menu_order',
                    'order'  => 'ASC',
                    'post_parent' => $post->ID
                $the_jukebox_query = new WP_Query( $jukebox_args );        
        <!--This is what needs to loop -->
                $loop = new WP_Query( $jukebox_args );
                    while ( $loop->have_posts() ) : $loop->the_post(); ?>
                    title:<?php echo apply_filters( 'the_title', $attachment->post_title ); ?>,
                    mp3:<?php echo wp_get_attachment_url( $attachment->ID, false ); ?>,
            <?php endwhile;?>
        <!--This would be the end of the loop -->
        ], {
            swfPath: "<?php echo get_template_directory_uri(); ?>/js",
            supplied: "mp3",
            wmode: "window"
share|improve this question
Please do not build JSON like that. Use json_encode(). – ThiefMaster Sep 18 '12 at 22:04
What is json_encode()? – David Deuster Sep 18 '12 at 22:40

Don't output javascript inline mixed with php. enqueue a single script and pass post-specific data to it via wp_localize_script.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.