WordPress pagination issue on homepage fixed

I recently came across an issue with WordPress and the ability to page through custom posts when set as the homepage.  It seems as though WordPress was ignoring part of the query that it was being sent or did not have a global value set for the page variable.  Basically what was happening was when you clicked to see page 2,3,4..etc, it would just reload the contents of page 1.

After much trial and error, and a bit of googling, I found the basic answer here.  Below is the fix which requires that you define a global variable for the paged portion of the query and also setting that variable in the paging links(here using the pagenavi plugin):
[info]

global $paged;
if( get_query_var( 'paged' ) )
$my_page = get_query_var( 'paged' );
else { if( get_query_var( 'page' ) )
$my_page = get_query_var( 'page' );
else $my_page = 1;
set_query_var( 'paged', $my_page );
$paged = $my_page; }
// default loop here, if applicable, followed by wp_reset_query();
$args = array( // other query params here, 'paged' => $my_page );
$my_query = new WP_Query( $args );
// custom loop code
wp_pagenavi( array( 'query' => $my_query ) );
wp_reset_query();

[/info]

Newsletter Updates

Enter your email address below and subscribe to our newsletter