Skip Navigation

[Resolved] Pass custom SONG post type's audio file into a player via Types shortcode

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 11 replies, has 2 voices.

Last updated by gaborG 6 years ago.

Assigned support staff: Shane.


I have an audioplayer that I can display with a shortcode, and it works really neat when I give it an actual link:

[sc_embed_player fileurl='<em><u>hidden link</u></em>

I have Song custom post types which have a custom Audio file parameter called "song file" in which I have the audio file for the song. I would like to pass the proper types code to the player so it loads the song, but the following doesn't work:

[sc_embed_player fileurl='[types field="song-file" preload="on"][/types]']

Can you guys help me what exactly should be the types short code what I place here? Thanks.



Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Gabor,

Our Types shortcode the for audio field does not allow you to retrieve the link for the audio file.

Instead it automatically generates the wordpress audio player for you.

To get the link itself we will need to write some custom code to retrieve it directly from the database.

Add this to your functions.php file.

// Add Shortcode
function get_meta_link( $atts ) {

  // Attributes
  $vals = shortcode_atts(
      'post_id' => '',
      'key' => '',
    ), $atts );

  // Code
 $link = get_post_meta( $vals['post_id'], $vals['key'] );

 return esc_url($link[0]);
add_shortcode( 'get_meta_link', 'get_meta_link' );

Likewise with the previous post you need to add this shortcode's name to the views compatibility settings if you wish to use it in views.

So the use case would be.

[sc_embed_player fileurl="[get_meta_link post_id='[wpv-post-id]' key='wpcf-audio_file']"]

All you need to do is change the key value to wpcf-{custom field slug}

Once you have done this then you should only get the url to the file.



Actually, if you could give me some directions where and how could I redesign the audioplayer to be only a button that switches from play to pause, I would prefer to use this built-in version and not load another player as well.
Would it be possible to customize it?



Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Gabor,

Unfortunately you are not able to customize the default audio player for wordpress.



Ah ok, I thought it was a player built by you guys.
The code now displays the player, but no sound. Not sure if it actually loads anything or not, but my guess is that it doesn't.


Should I just change the Audio file to URL instead? It sounds an easier solution since I don't need the built-in player then anyway.



Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Gabor,

No you do not need to change the audio file to a url field.

Could you let me have a look at things on the backend so I can see whats up?

The private fields will be enabled for your next post.



Now for some reason a '] appeared next to the audioplayer. No idea what brings it there. I reinstalled the player, it has all its original files now, without my modifications. If I remove the player, the '] disappears too, but if I use the player, it appears - but only on this one page. But even if I open it in private browsing mode, so it's not cache issue...
I purchased Toolset because I really did like the idea of not writing any PHP... but as I try to do the things I want to do, it turns out there is quite a lot of PHP to be done.



Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Gabor,

In order to get the correct name to use you need to check the slug of your audio file custom field.

You can check this by going to Types.

I tested the shortcode with the Compact WP audio player and it seems that the audio player plugin doesnt accept the shortcode as the parameter value.

The developers of the plugin may be looking for the url specifically in the fileurl attribute.

Does the shortcode work for you ?

If it doesn't work then we are bounded by to using the default wordpress audio player.

Please let me know and we can proceed from there .


Related song VIEW.jpg

I attached an image of the View what I want to make for this player.
The audioplayer is the left side rectangle, with the album cover at its background, and the player itself is no bigger than that rectangle.
The WP default player would mess up the entire design.

This structure (rectangular image left, text in the main area) will be displayed all over the site, displaying all kinds of post types in the same structure, and it would be an obvious fault if the song view would be different than all the rest.

What other solutions might we have, beside using the default WP player? This is the only minimalist audioplayer I found during an extensive search.

Would it perhaps be possible to extend the audioplayer plugin so that we could load the Song custom post into that instead, and then sort out the audiofile and the cover? I'm not sure, just an idea... I don't really know what is possible and what isn't since I don't know anthing about PHP.



Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Gabor,

Unfortunately i'm not aware of any customizations that can be done to the default audio player in order to get it to display like your screenshot.

What I suggest that you do is to contact the plugin's author for support on this one i.e Compact Audio player.

They may be able to shed some light on this as to why the audio player doesn't work with the shortcode.

The plugin's author would be best to help with this as we are able to provide a url for the plugin display the file in it's audio player.

Let me know if this helps.



Alright, I'm going to do that.
Thank you for your patience and help Shane.