0

I am using the Advanced Custom Fields plugin to create custom fields for post formats. I have a field that only displays when the audio post format is selected. This is a text filed where the user places a url from a soundcloud audio file, for example and then the the audio file should show on the front end of the post. However, I am having issues making this work. I have done the same process for the video post format and its working properly, however for audio files I am not having any luck so far.

The field I have created has the name of audio_post_format_url.

And the code bellow gets the value of that field and echoes it:

                $audio = get_post_meta( $post->ID, 'audio_post_format_url', true );
                echo wp_oembed_get( $audio );

But at the moment nothing gets echoed.. what am I doing wrong here?

1 Answer 1

1

Advanced Custom Field plugin uses get_field() to retrieve values.

Your code should be something like:

$audio = get_field('audio_post_format_url', $post->ID); 
var_dump( $audio ); # To make sure you're retrieving the right value
echo wp_oembed_get( $audio ); 

Note that get_field() does not need a second parameter, it will take the current post ID if omitted.

If var_dump( $audio ) displays false, then you should check your ACF key.

3
  • var_dump displays the url that has been added to the field audio_post_format_url. But the echo wp_oembed_get( $audio ); doesnt echo anything.
    – Madeirense
    Commented Jan 4, 2016 at 17:33
  • Is it something to to with audio files? because I have exactly the same set up for video urls for the video post format and it works just fine..
    – Madeirense
    Commented Jan 4, 2016 at 17:35
  • The url I was using was not working at all. I have tried another url to an audio file on soundcloud and it is working now. However, sometimes it doesn't show anything and only after I force a cache refresh (ctrl - f5) I get it to show.. Why would that be?
    – Madeirense
    Commented Jan 4, 2016 at 17:59

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.