Using Wp-Pagenavi with custom query and $paged variable

Posted: May 24, 2012 in Pagination
Tags: ,

WP-Pagenavi is a great plugin for paginating your WordPress Pages. But there are some cases when it is not working for custom queries like get_posts, query_posts or for WP_Query.

We can do it by using the following method for displaying Wp-pagenavi plugin so that it work fine with the custom queries:

global $paged;
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
// default loop here, if applicable, followed by wp_reset_query();

$args = array(
 // other query params here,
 'paged' => $paged

$my_query = new WP_Query( $args );

// custom loop code

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



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s