WordPress: Get Post Thumbnail Outside of Loop

I am trying to get the post thumbnail image for each accordion outside of the loop.

Currently, it’s setup with image placeholders but I need each thumb to represent the currently selected post.

<section class=”steps accordion-steps”>
<div class=”row”>
<?php
$posts_counter = 0;
$dataimg = ”;
$open = 0;
$args = array(
‘post_type’ => ‘servicesaccordion’,
‘orderby’ => ‘id’,
‘order’ => ‘DESC’,
‘post_status’ => ‘publish’
);
$myposts = new WP_Query( $args );
?>
<?php
if ($myposts->have_posts() ) {
echo ‘ <div class=”small-12 medium-7 large-5 column steps-wrapper e-in”>’;
$i = 0;
// Always start the list with a div.row

/* Start the Loop */
while ($myposts ->have_posts() ) {
$myposts ->the_post();
$i++;
$dataimg++;
$open++;
?>
<div>
<div class=”heading-accordion <?php if($open == 1){echo ‘open’;} ?> delay-<?php echo $i ?> change-image” data-image=”<?php echo $dataimg ?>”>
<div class=”top”>
<div class=”deco-wrapper”>
<div class=”inner-wrapper”></div>
</div>
<?php the_title();?>
</div>
<div class=”bottom” <?php if($open == 1){echo ‘style=”display: block;”‘;} ?>
<div class=”inner-wrapper”>
<p><?php the_content();?></p>
</div>
</div>
</div>
<?php
} // end of the while() loop
wp_reset_postdata();
echo ‘</div>’;
?>
<div class=”small-12 medium-5 column”>
<div class=”image-wrapper e-in”>
<div class=”image “>
<!–Post Iamge Will Show Herre According To The Posts–>
<img class=”lazy” data-src=”” alt=”” />
</div>
</div>
</div>
<?php }
?>

Read more here:: WordPress: Get Post Thumbnail Outside of Loop

Leave a Reply

Your email address will not be published. Required fields are marked *