Featured post loop displaying wrong post excerpt

Rate this post

Working on a WordPress theme issue, I have an archive page that has a featured post at the top that displays a featured image, post date, and excerpt along with other posts below it.

Running into an issue where the featured post has the correct title, correct image, but incorrect excerpt. It pulls in a different post’s text instead.

Any clue as to what is incorrect with the code below?

$args = array( 
    'numberposts' => '1' ,
    'post_type' => 'post',
    'meta_key' => 'post_featured', 
    'meta_compare' => '=', 
    'meta_value' => 1
$recent_posts = wp_get_recent_posts( $args );
$fID = 0;
foreach( $recent_posts as $recent ) : ?>
    <?php $fID = $recent["ID"]; ?>
    <div class="blog-listing featured_post">
        <a class="blog-image-lg" href="<?php echo get_permalink($recent["ID"]); ?>" style="background-image: url('<?php echo get_the_post_thumbnail_url( $recent["ID"], 'full' ); ?>');">
            <span>FEATURED POST</span>
            <?php echo get_the_post_thumbnail( $recent["ID"], 'post-thumbnails-big' ); ?>
        <div class="blog-info pull-left">
            <a href="<?php echo get_permalink($recent["ID"]); ?>"><h3 class="blog-title"><?php echo $recent["post_title"]; ?></h3></a>
            <span class="blog-date"><?php echo strtoupper(get_the_date('F j, Y')); ?></span>
            <p><? echo the_excerpt(); ?></p>
            <p class="readmore-wrapper"><a class="readmore" href="<?php echo get_permalink($recent["ID"]); ?>">READ MORE &raquo;</a></p>



Change <? echo the_excerpt(); ?> to <?php echo get_the_excerpt($recent["ID"]); ?>.

the_excerpt() does not work in your case as you are not inside a WP Loop, just a regular for loop.

Leave a Reply

Your email address will not be published.

Back to top button