Stickied Posts on Every Page with Pagination

I’m trying to have 3 stickied posts at the top of every blog page (i.e., even if you’re on page 27, you still see the 3 stickied posts at the top).

I understand you need two queries, and I’ve gotten it working mostly, but my pagination is repeating the same non-stickied posts on every page. What am I messing up?

$sticky_posts = get_posts(array(
    'post__in' => get_option('sticky_posts'),
    'posts_per_page' => 3
));
$regular_posts  = get_posts(array(
    'post__not_in' => get_option('sticky_posts'),
    'posts_per_page' => 10
));

<div class="sticky-posts">

    <?php
        foreach( $sticky_posts as $post ) {
            setup_postdata( $post );
            the_title();
        }
        wp_reset_postdata();
    ?>

</div>

<div class="regular-posts">

    <?php
        foreach( $regular as $post ) {
            setup_postdata( $post );
            the_title();
        }
    ?>

    <div class="pagination">
        <div class="prev">
            <?php previous_posts_link("PREVIOUS"); ?>
        </div>
        <div class="next">
            <?php next_posts_link("NEXT"); ?>
        </div>
    </div>

    <?php endif; wp_reset_postdata(); ?>

</div>

Read more here: Stickied Posts on Every Page with Pagination

Leave a Reply

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