Do you have experience in web development and a passion for writing articles? If so, you might want to contact us. Learn more » macys promo code 2019

WordPress WP-PageNavi plugin not working. How to fix?


About this article: Posted in: Learned along the way
By: Blockcoder ( Admin ) / 06.09.2013
Stats: Comments Off / Views: 223
Tags: , ,

Everything is right and… (again) not

Hi again, I have been fighting with this plugin lately: wp-pagenavi. It should give me the pagination for my blog — but not. I have installed it correctly and trying to get it working with “WP_Query();”. I don’t get it, my loop is correct but WP-PageNavi doesn’t work. –Oh s*it sherlock, I have solved the problem for you.

How to paginate with WP-PageNavi?

Okay, the solution is a bit annoying. Couple of working hours wasted again into oblivion. This is the better way of doing things. Enough talking — let’s do this.

Solution for the “WP_Query()”:

$q = new WP_Query( array( 'posts_per_page' => 5, 'paged' => get_query_var('page')));
while ( $q -> have_posts()) : $q -> the_post();
  //stuff here
wp_pagenavi( array( 'query' => $q ));  // *

* You need to send the query for “wp_pagenavi()” -function:

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

That’s it for the “WP_Query()”. It should work.

The old way — “query_posts()”

Okay, the old way also works just fine with WP-PageNavi plugin. I would say it’s more simplier that the WP_Query() — but according to the developer “the WP_Query() is better, because it has less side-effects”. I really don’t know what those “side effects” are, but it doesn’t matter.

For now, let’s focus on the old way: query_posts() right usage:

query_posts( array( 'cat' => 1, 'paged' => get_query_var('page') ) );
while ( have_posts()) : the_post();
  //stuff here

It should work just fine. Let me know it this helped you out. Here you can find the developer’s guide for the correct usage of WP-PageNavi plugin.