• I’ve managed to get the pagination working with custom posts working on my wordpress theme. I have only one problem left and i can’t find any solutions for it.

    I have 9 posts I want to display (4 per page). So I should get 3 pages. Instead i get 12 pages. This is for 48 posts (which is the number of the total posts).

    This is my code:

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $loop = new WP_Query( array(
    				'post_type' => 'freemz_portfolio',
    				'posts_per_page' => 4,
    				'orderby'=> 'menu_order',
    				'paged'=>$paged,
    				'orderby'=> 'menu_order'
    				) ); 
    
    while ( $loop->have_posts() ) : $loop->the_post();
    ?>
    
     <--- output code -->
    
    <?php endwhile; ?>
    
    <!-- page navi -->
     <div class="pagenavi">
      <?php if(function_exists('wp_pagenavi')) { wp_pagenavi();} ?>
     </div>
    <!-- page navi end -->

    When you check page 4, 5 etc. There is no result. The query is giving the correct results. But somehow the pagination is not based on the posts from the query.

    Anyone got a bright idea?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter geerthoekzema

    (@geerthoekzema)

    In addition:
    The posts are displayed via index.php. If I use a page-template with the workaround here: https://weblogtoolscollection.com/archives/2008/04/19/paging-and-custom-wordpress-loops/ the number of pages is correct. Only the paginations doesn’t work. When I go to page 2, I’ll see the results of page one.

    When I echo the $paged var, this is always 1.

    Thread Starter geerthoekzema

    (@geerthoekzema)

    Well, got it fixed.

    Old code:

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $loop = new WP_Query( array(
    				'post_type' => 'freemz_portfolio',
    				'posts_per_page' => 4,
    				'orderby'=> 'menu_order',
    				'paged'=>$paged,
    				'orderby'=> 'menu_order'
    				) ); 
    
    while ( $loop->have_posts() ) : $loop->the_post();

    New code:

    $loop = new WP_Query( array(
    				'post_type' => 'freemz_portfolio',
    				'posts_per_page' => 4,
    				'orderby'=> 'menu_order',
    				'paged'=>$paged,
    				'orderby'=> 'menu_order'
    				) );
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    
    while ( $loop->have_posts() ) : $loop->the_post();

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom posts pagination based on all posts’ is closed to new replies.