Support

Account

Home Forums General Issues Audio playlist field

Solved

Audio playlist field

  • Hi everybody,
    A WordPress audio playlist is a list of selected local audio tracks.
    It’s inserted in content as a shortcode very similar to images gallery.
    ie: [playlist ids="308,314,312,310,316,306"]

    Wordpress then wrap the playlist with a multitrack audio player.

    I can’t find a way to add such shortcode with ACF.

    Any clue ?

    Thanks in advance

  • I think I found a reliable way by using gallery field:

    $audio_playlist = get_field( ‘audio_playlist’ ); //gallery field
    $playlist = array();
    foreach ( $audio_playlist as $audio ){
    array_push ( $playlist, $audio[“ID”] );
    }
    echo ‘<div class=”audio-container”‘.do_shortcode(‘[playlist ids="'.implode(',',$playlist).'"]‘).'</div>’;

    What do you think?

  • Looks like it should work to me. You could probably also use a repeater with a file field. Either way would work.

  • Hi John, thanks for your reply.
    It works pretty well, yes.
    The nice thing with the gallery field is that it lets you pick all the playlist tracks at once.

    I’d definitely use a real Playlist plugin though; it would filter out non-audio files first. I don’t have the skill to write one :'(

  • It is possible, with some work, to filter the files shown for a gallery field. https://support.advancedcustomfields.com/forums/topic/filter-gallery-items/

  • Many thanks for the info.
    The following works perfectly:

    add_filter( 'ajax_query_attachments_args', 'show_audio_attachments', 10, 1 );
    function show_audio_attachments( $query=array() ) {
    	if( $_POST['query']['_acfuploader'] && $_POST['query']['_acfuploader'] == 'field_589471f6b171a' ) {
    		$query['post_mime_type'] = 'audio';
    	}
      return $query;
    } 

    The downside may be is that it relies on hard coded field reference, but if I’m to change the fields structure I’ll have other problems to deal with anyways.

    Also I have to make it work with Media Library Assistant plugin.
    I’ll keep you posted…

  • Yup!
    For Media Library Assistant users, the call is not in
    ajax_query_attachments_args
    but in
    mla_media_modal_query_filtered_terms

    All is ok for me.
    John, thank you again for your help.

  • This reply has been marked as private.
  • Not able to set the previous post ‘public’. Don’t know why.
    Here it is:

    Native WordPress hook:
    add_filter( 'ajax_query_attachments_args', 'show_audio_attachments', 10, 1 );
    Media Library Assistant hook:
    add_filter( 'mla_media_modal_query_filtered_terms', 'show_audio_attachments', 10, 1 );

     function show_audio_attachments( $query=array() ) {
    	if( $_POST['query']['_acfuploader'] && $_POST['query']['_acfuploader'] == 'field_589471f6b171a' ) {
    		$query['post_mime_type'] = 'audio';
    	}
      return $query;
    }
Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.