I’m having some trouble with my WordPress pagination.
Everytime I click on a pagination link, it takes me to the next page, but the pagination doesn’t update (so, for example, when I click on page “2”, the pagination still thinks it’s on page “1”.
It’s an odd bug, but it’s frustrating me none the less (especially seeing as I’ve been pulling my hair out for two days just trying to get pagination to work full stop!).
Here’s my pagination code:
function paginate() {
global $wp_query, $wp_rewrite;
$wp_query->query_vars['paged'] > 1 ? $current = $wp_query->query_vars['paged'] : $current = 1;
$pagination = array(
'base' => @add_query_arg('page','%#%'),
'format' => '',
'total' => $wp_query->max_num_pages,
'current' => $current,
'show_all' => true,
'type' => 'list',
'next_text' => '»',
'prev_text' => '«'
);
if( $wp_rewrite->using_permalinks() )
if ( is_home() ) {
//fixes index.php weird error on how it displays the pagination URL which causes errors only on index.php
$pagination['base'] = user_trailingslashit( trailingslashit( remove_query_arg( 's', get_pagenum_link( 1 ) ) ) . '?page=%#%/', 'paged' );
} else {
$pagination['base'] = user_trailingslashit( trailingslashit( remove_query_arg( 's', get_pagenum_link( 1 ) ) ) . 'page/%#%/', 'paged' );
}
if( !empty($wp_query->query_vars['s']) )
$pagination['add_args'] = array( 's' => get_query_var( 's' ) );
echo paginate_links( $pagination );
}
And, if it’ll help, here’s the loop that’s being called:
if ( get_query_var('paged') ) { $paged = get_query_var('paged'); } else if ( get_query_var('page') ) {$paged = get_query_var('page'); } else {$paged = 1; }
$archiveArgs = array( 'posts_per_page' => 8, 'paged' => $paged);
$archiveLoop = new WP_Query();
$archiveLoop->query( $archiveArgs );
while ( $archiveLoop->have_posts() ) : $archiveLoop->the_post(); ?>
Thankyou so much for your help in advance!
try to change your
As
havent tested. could be this problem if not then wats yor url when clicked on the pagination