Posted By

javifr on 10/29/10


Tagged

wordpress audio Attached


Versions (?)

Attached files to single - audio


 / Published in: PHP
 

  1. function get_attached_audio($number=NULL){
  2.  
  3. if($number == NULL ) $number = -1;
  4.  
  5. global $post;
  6.  
  7. $args = array(
  8. 'post_type' => 'attachment',
  9. 'numberposts' => $number,
  10. 'post_status' => null,
  11. 'post_parent' => $post->ID,
  12. 'orderby' => 'menu_order'
  13. );
  14.  
  15. $attachments = array_reverse(get_posts($args));
  16.  
  17. $audios = array();
  18.  
  19. if ($attachments) {
  20. foreach ($attachments as $attachment) {
  21.  
  22. if( $attachment->post_mime_type == "audio/mpeg"){
  23. $audio = wp_get_attachment_url($attachment->ID,'full',false);
  24. $audios[] = array("url" => $attachment->guid, "caption" => $attachment->post_title);
  25. }
  26. }
  27. }
  28.  
  29. return $audios;
  30. }
  31.  

Report this snippet  

You need to login to post a comment.