WordPress.org

Ready to get started?Download WordPress

Forums

wp_get_attachment_url not showing anything (4 posts)

  1. nolageek
    Member
    Posted 3 years 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.

  2. esmi
    Theme Diva & Forum Moderator
    Posted 3 years ago #

  3. nolageek
    Member
    Posted 3 years 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

  4. nolageek
    Member
    Posted 3 years 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);

Topic Closed

This topic has been closed to new replies.

About this Topic