0

Hey Guys,

I am having an issue with my custom field for my download button within post loop. It is supposed go to an external link, but when I enter the "download_url" value it ends up linking to "www.mysite.com/blog/http://www.downloadurl.com" instead of "http://www.downloadurl.com". So basically it is adding my blog url before my custom field. How would I get just the value of my custom field?

Here is my code:

<a href="<?php if (get_post_meta($post->ID, 'download_url', true)) { ?><?php echo get_post_meta($post->ID, "download_url", $single = true); ?><?php } ?>"><span>Download</span></a>

Any help would be greatly appreciated! Thank you for your time : )

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by wpmonster
0

I think, you forgot to add http:// to your custom field value.

<?php
$downloadurl = get_post_meta($post->ID, 'download_url', true);
if($downloadurl != ""){
echo '<a href="'.$downloadurl.'"><span>Download</span></a>';
}
?>

It works fine :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.