wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); Getting thumb from wrong loop

I am using a plugin which sets the thumbail for your fb share image. The src is

<?php echo wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>

Which was working fine, but not it’s showing thumb X on every page (rather then the currect thumbnail) I found the problem is I have a loop in the sidebar.

Read More

Is there a way to make

<?php echo wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>

Get its attachment from the FIRST loop (as this code is at the bottom of the page)

Or is there some other hack to make it get it from the first loop?

Related posts

Leave a Reply

1 comment

  1. Set a variable in the first loop like:

    $saved_post_id = $post->ID;
    

    Then later down the page use that variable like:

    echo wp_get_attachment_url( get_post_thumbnail_id( $saved_post_id ) );