4

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.

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?

2
  • echo wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); Is the code,sorry! Commented Jan 11, 2012 at 22:07
  • Write code between backcomments (this character: `)
    – turbonerd
    Commented Jan 11, 2012 at 22:10

1 Answer 1

4

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 ) );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.