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.


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);
| improve this answer | |
  • 1
    Please format your code so that it is easily readable. – Nilambar Sharma Jun 24 '15 at 5:34
  • Thanks for pointing that out. I've added the instantiation. But I'm not getting working pagination. – dave dave Jun 25 '15 at 11:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.