Pagination – works on local but not live dev!

Can anyone please shed some light as to why the following to print out page numbers works on my local dev server but not on my live server?

Both server are running same version of PHP.

Read More

My Loop

<?php
global $paged;
$args = array(
    'orderby' => 'post_date',
    'posts_per_page' => 5,
    'paged' => $paged
);
$query = new WP_Query($args);
if($query->have_posts()) : while ($query->have_posts()) : $query->the_post();
//do stuff
endwhile; ?>

My Pagination

<?php echo '
<div id="pagination">
<a class="first page button" href="'.get_pagenum_link(1).'">[First]</a>';
for($i=1;$i<=$query->max_num_pages;$i++)
echo '<a class="page button" href="'.get_pagenum_link($i).'">'.$i.'</a>';
echo '<a class="last page button" href="'.get_pagenum_link($query->max_num_pages).'">[Last]</a></div>
';
endif;
wp_reset_query();
?>

The issue clearly lies within:

for($i=1;$i<=$query->max_num_pages;$i++)

The first & last print out fine – the page numbers do not.

Thanks in advance

EDIT

If i do this it works:

for($i=1;$i<=99;$i++)

So the issue is with:

$query->max_num_pages;

Any more thoughts?

Related posts

Leave a Reply

1 comment

  1. try this

    <?php 
    //global $wp_rewrite;
    $loop->query_vars['paged'] > 1 ? $current = $loop->query_vars['paged'] : $current = 1;
    
    $pagination = array(
        'base' => @add_query_arg('page','%#%'),
        'format' => '',
        'total' => $loop->max_num_pages,
    
        'current' => 0,
        'show_all' => true,
        'prev_next'    => true,
        'prev_text'    => __('&laquo; Back'),
        'next_text'    => __('Newxt&raquo;'),
        'type' => 'plain'
        );
    
    if( $wp_rewrite->using_permalinks() )
        $pagination['base'] = user_trailingslashit( trailingslashit( remove_query_arg( 's', get_pagenum_link( 1 ) ) ) . 'page/%#%/', 'paged    ' );    
    
        echo "<div class="pagination" >";    
    echo paginate_links( $pagination );    
    echo "</div>";    
    ?>