Tural
Tural

Reputation: 31

How to get field value in Wordpress shortcode?

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

?>

Upvotes: 2

Views: 395

Answers (2)

Tural
Tural

Reputation: 31

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

Upvotes: 1

mikerojas
mikerojas

Reputation: 2338

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

?>

Upvotes: 1

Related Questions