612-293-8629 [email protected]

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!



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



Call Now

Enroll in Our Free Beginner WordPress Class by Email

Never feel powerless in WordPress again!  Become a WordPress superstar for free in only minutes a day!

Our Beginner WordPress Email Class is delivered to your inbox!

Learn More 

You Have Successfully Enrolled! Prepare For Amazing!