Home > Net >  How to get field value in Wordpress shortcode?
How to get field value in Wordpress shortcode?

Time:10-07

I try to get field value in shortcode. But it is not work. How can I do it? "audio_url" is field meta name.

<?php
$audio_source = get_post_meta($post->ID, 'audio_url',true);

echo do_shortcode('
[zoomsounds_player config="motionplayer" source="{$audio_source}"]
');

?>

CodePudding user response:

If $audio_source is the expected value... looks like you need to swap your quotes to use PHP Variable Interpolation like so:

<?php
$audio_source = get_post_meta($post->ID, 'audio_url',true);

echo do_shortcode("[zoomsounds_player config='motionplayer' source='{$audio_source}']");

?>

CodePudding user response:

I already found a solution. I put it in if someone needs it.

$audio_source = get_field('audio_url');
if($audio_source){
echo do_shortcode('
[zoomsounds_player config="motionplayer" source="'. $audio_source .'"]
');
}
  • Related