612-293-8629 HELLO@THEMIGHTYMO.COM

For my music archive WordPress theme, I needed to use wp_get_attachment_url in functions.php to grab a url that uses a custom field as follows:

<?php wp_get_attachment_url(get_post_meta($post->ID, 'Audio File', true)); ?>

For some reason, WordPress wants to grab the post url rather than the file url. To fix this, I simply had to call the global $post variable as follows:

<?php global $post; ?>
<?php wp_get_attachment_url(get_post_meta($post->ID, 'Audio File', true)); ?>

That’s it! I am sure there is a different/better way to do this, so if you know how to accomplish this a different/better way, please let me know!

Thanks!

PHONE, EMAIL, TEXT

We love to communicate: phone, email, text, Facebook, Twitter, LinkedIn, you name it.

LOCATIONS

PAYMENTS ACCEPTED

Call Now

Enroll in Our Free Beginner WordPress Class - delivered to your Email Inbox!

Become a WordPress superstar for FREE in only minutes a day!  Our free Beginner WordPress Email Class will be delivered to your inbox!

Learn More 

You Have Successfully Enrolled! Prepare For Amazing!