Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've also posted this on the wordpress support forums, for scribu's wp-pagenavi plugin:

http://wordpress.org/support/topic/plugin-wp-pagenavi-custom-query-form-submit-part-2?replies=1

My situation:

I am using a form to create a custom query that displays posts from a custom post type archive matching a certain custom field (Eg: For "custom-post-type" show only posts that have the "custom-field" value selected from the form). I know, it's called filtering :P

My custom post type archive looks like this:

www.example.com/custom-post-type-archive

(note that I use the "post name" permalink setting)

Upon form submission, the new url is this:

www.example.com/custom-post-type-archive?key=value

The custom query is set to show only posts with value of key custom field:

$value = $_GET['value'];
$paged = get_query_var('page');
$args = array(
        'post_type' => 'custom-post-type',
        'meta_key' => 'key',
        'meta_value' => $value,
        'paged' => $paged,
        'posts_per_page' => 10
);
$my_query = new WP_Query($args);

After the loop I have:

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

The query works, I get the right results. But I have problems getting pagination to work. When I go to the next page, I get this url:

www.example.com/custom-post-type-archive/page/2?key=value

but pagination still shows like I'm on the first page and the results are the same.

If I manually enter:

www.example.com/custom-post-type-archive?key=value&page=2

I get the right results (from page 2), but the all navigation links are the same as the url I manually entered above.

Please help (hints, resources, anything).

Thx, Radu

share|improve this question
1  
I also have similar problem, did you found the solution yet? Can you share it here? –  dev-jim Oct 24 '12 at 14:21
    
Any solution for this? –  p.a. Nov 5 '12 at 17:45
    
@p.a, @tc.k, I solved the problem using the paged parameter (instead of page) in get_query_var and implementing ajax pagination just as @swtshweta pointed out. I think it would have worked even without ajax. –  rereradu Nov 6 '12 at 19:03
    
Yep, the solution is definitely using paged instead of page as a parameter (I am using WP 3.3.2 and WP-pagenavi 2.82). Works without Ajax pagination, although using that technique looks awesome :) –  rereradu Nov 6 '12 at 19:10
add comment

6 Answers 6

You can try implementing ajax based pagination for wp-pagenavi plugin(see http://wordpressapi.com/2011/05/16/add-ajax-pagination-in-wordpress-blog/ for reference ). I think this will solve your issue.

share|improve this answer
add comment

Probably the problem has been already solved here: http://stackoverflow.com/a/13216165/1801379

You ca also get some idea from here: http://wordpress.stackexchange.com/a/4131/23290

share|improve this answer
add comment

Here are the solutions I found (note I'm using WP 3.3.2 and WP-Pagenavi 2.82):

Solution 1: Using paged instead of page as a get_query_var parameter.

Solution 2 Using ajax based navigation, just as in the article swtshweta pointed out. (using Ajax, pagination works properly even with the page parameter).

share|improve this answer
add comment

Because this comes up in search, I'd like to point out that WP Page Navi ( as of version 2.74 ) now supports custom queries.

The WP_Pagenavi FAQ links to the following article to explain how to use the Pagenavi plugin with a secondary query by passing the wp_pagenavi() function a query parameter.

From the tutorial:

$my_query = new WP_Query();

while ( $my_query->have_posts() ) : $my_query->the_post();
    the_title();
    // more stuff here
endwhile;

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

wp_reset_postdata();    // avoid errors further down the page
share|improve this answer
add comment

Strangely the answer proposed does not show anything on my browser. I have the latest WP and latest Chrome browser. Thanks anyway.

Although wp_pagenavi appears correctly, and the links show /page2/, /page3/ and so on, and I have added the $paged or $page attribute to my wp_query, always the first page appears.

share|improve this answer
    
are you calling the wp_pagenavi function correctly: wp_pagenavi(array('query' => $your_custom_query)); ? –  rereradu Nov 7 '12 at 14:07
    
I tried both but none worked. I realised that the variable $paged variable is always submitted as empty. –  p.a. Nov 12 '12 at 7:39
add comment

Radu, The following solution worked for me: I modified a standard paging code, and made it submit "&page=xxx" and catched $page as form submission variable. It now works perfect.

Notice the last line, this is where modifications happened.

global $paged;
$paged = ($_GET["page"]) ? ($_GET["page"]) : 1; //this is where I catch the requested page

function pagenavi( $found_posts, $p = 2 ) { // pages will be show before and after current page
  if ( is_singular() ) return; // don't show in single page
  global $paged;
  $max_page =  intval($found_posts / 10) + 1;
  echo('max_page=' . $max_page);
  if ( $max_page == 1 ) return; // don't show when only one page
  if ( empty( $paged ) ) $paged = 1;
  echo '<span class="pages">Page: ' . $paged . ' of ' . $max_page . ' <BR></span> '; // pages
  if ( $paged > $p + 1 ) p_link( 1, 'First' );
  if ( $paged > $p + 2 ) echo '... ';
  for( $i = $paged - $p; $i <= $paged + $p; $i++ ) { // Middle pages
    if ( $i > 0 && $i <= $max_page ) $i == $paged ? print "<span class='page-numbers current'>{$i}</span> " : p_link( $i );
  }
  if ( $paged < $max_page - $p - 1 ) echo '... ';
  if ( $paged < $max_page - $p ) p_link( $max_page, 'Last' );
}
 function p_link( $i, $title = '' ) {
  if ( $title == '' ) $title = "Page {$i}";
  echo "<a class='page-numbers' href='", esc_html( $_SERVER['REQUEST_URI'] . '&page=' .$i ), "' title='{$title}'>{$i}</a> ";

}

share|improve this answer
    
<<To stachexchange admins>> please consider my answer as response to my bounty faq. The solutions offered by members were worthwile but did not work for me, since the proposed solution $paged = get_query_var('page'); was always EMPTY for my system. Thanks. –  p.a. Nov 12 '12 at 9:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.