skip to Main Content

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}"]
');

?>

2

Answers


  1. Chosen as BEST ANSWER
    $audio_source = get_field('audio_url');
    if ($audio_source) {
        echo do_shortcode('[zoomsounds_player config="motionplayer" source="'
            . $audio_source . '"]');
    }
    

  2. 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}']");
    
    ?>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search