Take the 2-minute tour ×

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 );
                    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
add comment

1 Answer

You are attempting to use the var $attachment to access your attachments data. But you don't ever set your $attachment var to actually contain any data, so its currently empty. As you have set up your post data within your loop using $loop->the_post(); you should be able to;

title:<?php echo apply_filters( 'the_title', get_the_title() ); ?>,
mp3:<?php echo wp_get_attachment_url( get_the_ID(), false ); ?>,


Take note of the point about re setting your post data using wp_reset_postdata().

share|improve this answer
add comment

Your Answer


