Title: Load Attachments into JavaScript
Last modified: August 20, 2016

---

# Load Attachments into JavaScript

 *  [ddeuster](https://wordpress.org/support/users/ddeuster/)
 * (@ddeuster)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/load-attachments-into-javascript/)
 * I’ve been working on a custom jPlayer for our theme. Right now I’m going through
   the process of integrating the script to load in the mp3 files and would like
   to do that via files that are attached to the post. I’m using the post_mine_type
   to filter out those files. Below is the code I’m working on to loop through the
   various attachments in the JavaScript that loads them.
 * I’m having some difficulty getting them to load and to loop properly. Any help
   would be greatly appreciated. I’m sure its something minor that I’m missing.
 *     ```
       <!--Begin Jplayer Playlist -->
       		<script type="text/javascript">
       		//<![CDATA[
       		$(document).ready(function(){
   
       			new jPlayerPlaylist({
       				jPlayer: "#jquery_jplayer_1",
       				cssSelectorAncestor: "#jp_container_1"
       			}, [
       			<!--This is what needs to loop -->
       			 <?php
               		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 );
               	?>
   
               		<?php if ($the_jukebox_query->have_posts()) : ?>
       					{
       						title:<?php echo apply_filters( 'the_title', $attachment->post_title ); ?>,
       						mp3:<?php wp_get_attachment_link( $attachment->ID, false ); ?>,
       					},
       				<?php endif; ?>
   
       			<!--This would be the end of the loop -->
       			], {
       				swfPath: "<?php echo get_template_directory_uri(); ?>/js",
       				supplied: "mp3",
       				wmode: "window"
       			});
       		});
       		//]]>
       		</script>
       <!--End Jplayer Playlist -->
       ```
   

The topic ‘Load Attachments into JavaScript’ is closed to new replies.

## Tags

 * [array](https://wordpress.org/support/topic-tag/array/)
 * [javascript](https://wordpress.org/support/topic-tag/javascript/)
 * [posts](https://wordpress.org/support/topic-tag/posts/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [ddeuster](https://wordpress.org/support/users/ddeuster/)
 * Last activity: [13 years, 7 months ago](https://wordpress.org/support/topic/load-attachments-into-javascript/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
