WordPress.org

Ready to get started?Download WordPress

Forums

WP Custom Query with Pagination not working (1 post)

  1. PuNK DeSi
    Member
    Posted 1 year ago #

    hi...
    M using wp-pagenavi v.2.83 for pagination

    I tried this code to query posts from some categories.

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    	  query_posts("cat=14,15,16,17,42&paged=$paged");
    if (have_posts()) :
    while ( have_posts() ) : the_post();
    	the_title();
    	// more stuff here
    endwhile;
    if(function_exists('wp_pagenavi')) { wp_pagenavi(); }
    wp_reset_query();
    	else :
    	   include(TEMPLATEPATH."/nopost.php");
    	endif;

    with this I got all pages pagination shown but works only upto page 9
    but on 10th page and onwards I got 'Not Found' Error Page.

    also tested 2nd method as described here:

    $temp = $wp_query;
    	global $wp_query;
    	$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    	$myquery = new WP_Query('cat=14,15,16,17,42&paged=' . $paged);
    if($myquery ->have_posts()) {
    while ($myquery->have_posts() ) : $myquery->the_post();
    	the_title();
    	// more stuff here
    endwhile;
     if(function_exists('wp_pagenavi')) {
         wp_pagenavi( array('query' => $myquery));
         }
    	wp_reset_postdata();
    	$wp_query = null; $wp_query = $temp;
    else {
    	include(TEMPLATEPATH."/nopost.php");
        }

    This code also shows all pages in pagination but works upto 3 pages only 4th page & onwards displays 'NOT FOUND' page.

Topic Closed

This topic has been closed to new replies.

About this Topic