nolageek
Member
Posted 1 year ago #
I've been going over all of the documentation and I can't figure out why this isn't working:
echo wp_get_attachment_url($post_id);
This works:
echo get_attachment_link($post_id, 'medium');
Is wp_get_attachment_url deprecated? I don't want the attachment's page. There's no mention of a replacement function to return the full URL to the attached image.
nolageek
Member
Posted 1 year ago #
I tried that too - comes up blank.
I'm trying to modify the output of the Favorites Post plugin. Here is their code with my additions (just testing it now):
if ($favorite_post_ids):
foreach ($favorite_post_ids as $post_id) {
$p = get_post($post_id);
echo "<li>";
echo "<a href='".get_permalink($post_id)."' title='". $p->post_title ."'>" . $p->post_title ."</a> ";
echo wp_get_attachment_url($post_id);
echo get_attachment_link($post_id, 'medium');
The output of this is correct except the wp_get_attachment_url is blank.
ie:
I get the title of the post (from the original plugin) then http://domain-name.com/?attachment_id=84
nolageek
Member
Posted 1 year ago #
I even tried using explicitly using 84 instead of $post_id and that did the same thing.
This also doesn't work for me:
echo get_attached_file($post_id);
nor does
echo get_attached_file(84);