I've got a custom loop for which I'd like pagination.

The codex and examples I've found online indicate that I should get pagination as long as I pass the 'paged' query variable into the loop as the 'page' variable ( or 'page' for a static front page). However in my case this simply doesn't work.

I'm not working with a static front page: just a normal Page.

What I'm seeing is that for every page that I navigate to, I get the same posts.

This is the template I'm working with:

<div class="container latest-posts group">
    <div class="row">

    <div class="container">     
            <header class="section-header row">
                <div class="col-xs-12">
                    <h2 "><?php the_title()  ?></h2>

        <section id="latest-posts" class="col col-xs-12 col-sm-8 js-masonry">
             *  latest posts
        if ( get_query_var('paged') ) $paged = get_query_var('paged');
            if ( get_query_var('page') ) $paged = get_query_var('page');

            $args = array(
                'posts_per_page' => 7,
                    'offset'    => '5',
                    'paged' => $paged
            ) ;

            $my_query = new WP_Query($args) ;

            while ($my_query->have_posts()) : $my_query->the_post(); ?>
            <article class="frontpage-news-article">
                <div class="inner">
                        <a href="<?php the_permalink()  ?>">
                            <?php the_title()  ?>

                    <?php   include( get_stylesheet_directory() . "/templates/post-meta.php") ;   ?>

                    <p><?php  the_excerpt(); ?></p>
                    <p><a href="<?php echo get_permalink()  ?>">read more</a></p>
            <?php endwhile; ?>

        // Reset postdata

            <footer class="paging group">
                <?php next_posts_link('&laquo; Older Entries') ?>
                <?php previous_posts_link('Newer Entries &raquo;') ?>

                    wp_pagenavi( array(
                        'query' =>$my_query )

        </section> <!-- ENDS #latest-posts  -->

        <aside class="sidebar col-xs-12 col-sm-4 group" role="complementary">
                <?php   dynamic_sidebar('primary') ?>
        </aside><!-- .sidebar -->

    </div> <!-- ENDS .container -->

As you can by the code, I've been trying both wordpress's native pagination calls and also wp-pagenavi. Both of them yield the same undesirable results.

  • 1
    possible duplicate of Pagination on a custom page template
    – Robert hue
    Commented Jun 24, 2015 at 5:16
  • 'offset' will not work together with 'paged' in one query; try to create somehow a different way to exclude the first five posts.
    – Michael
    Commented Jun 24, 2015 at 17:25

1 Answer 1


By seeing your code, you are creating the $args array but not passing it to the WP_Query. Try using the below way.

$args = array(
     'posts_per_page' => 7,
      'offset'    => '5',
      'paged' => $paged
 ) ;
$my_query =new WP_Query($args);
  • 1
    Please format your code so that it is easily readable. Commented Jun 24, 2015 at 5:34
  • Thanks for pointing that out. I've added the instantiation. But I'm not getting working pagination.
    – dave dave
    Commented Jun 25, 2015 at 11:47

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.