2

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

?>
1
  • What is happening? Have you confirmed that $audio_source is the expected value? Commented Oct 6, 2022 at 18:11

2 Answers 2

1

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

?>
Sign up to request clarification or add additional context in comments.

1 Comment

I already found a solution. Thanks
1
$audio_source = get_field('audio_url');
if ($audio_source) {
    echo do_shortcode('[zoomsounds_player config="motionplayer" source="'
        . $audio_source . '"]');
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.