Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
    
echo wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); Is the code,sorry! –  user1110237 Jan 11 '12 at 22:07
    
Write code between backcomments (this character: `) –  dunc Jan 11 '12 at 22:10
add comment

1 Answer

set a variable in the first loop. like <?php $saved_post_id = $post->ID; ?> then later down the page use that variable like: <?php echo wp_get_attachment_url( get_post_thumbnail_id( $saved_post_id ) ); ?>

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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