0

I have a latest posts slider working nicely. I would like to push a specific post (ID 123) to always appear first. I believe I could run multiple queries but every attempt has failed. I'm running out of ideas and steam! So, the featured post first, then the latest posts by date (not a problem if the featured post is duplicated when shown in date order.

<div class="feed">
    <h2>Latest</h2>
    <div id="feed" class="owl-carousel">
        <?php $args = array( 'numberposts' => 10, 'post_status'=>"publish",'post_type'=>"post",'orderby'=>"post_date");
        $postslist = get_posts( $args );
        foreach ($postslist as $post) : setup_postdata($post); ?>
        <div class="inner">
           <h3><?php the_title(); ?></h3>
           <?php the_excerpt(); ?>
           <a href="<?php the_permalink(); ?>" title="<?php the_title();?>">More</a>
        <div>
        <?php endforeach; ?>
    </div>
</div>

1 Answer 1

0

Since you're using get_posts() rather than WP_Query, it's sufficient to retrieve the specific post separately with get_post(), and then add it to the beginning of the results array with array_unshift():

$postslist     = get_posts( $args );
$featured_post = get_post( 123 );

array_unshift( $postslist, $featured_post );

foreach ( $postslist as $post ) : setup_postdata($post);
1
  • Perfect. Thank you. Commented Jul 15, 2019 at 15:49

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.