[resolved] Custom Post type pagination not working (9 posts)

  1. sydmeeran
    Posted 1 year ago #

    Hi everyone,

    i have created custom post-type testimonial and i am getting a 404 with pagenavi pagination..

    My Custom Post-type is Testimonials and i have two taxonomies

    1) Residential
    2) Commercial

    I have three templates

    1) Testimonials ( show testimonials from both category)
    2) Residential
    3) Commercial

    It is working fine in Testimonial archive but in taxonomy pages it is not working..

    Testimonial Archive Code is below (working) and URL structure is
    example.com/testimonials/ and when paginating example.com//testimonials/page/2...n

    $posts_per_page = 6;
    	$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    	$testimonial_query = new WP_Query(
            'post_type' => 'testimonials',
          	'paged' => $paged,
          	'posts_per_page' => $posts_per_page,

    My code for taxonomy page is below and URL structure is
    example.com/testimonials/residential and example.com/testimonials/residential/page/2...n

    $posts_per_page = 4;
    if ( get_query_var( 'paged' ) ) {
    $paged = get_query_var( 'paged' );
    } elseif ( get_query_var( 'page' ) ) {
    $paged = get_query_var( 'page' );
    } else {
    $paged = 1;
                                $query = new WP_Query(array(
                                'post_type' => 'testimonials',
                                //'testimonial_category' => 'commercial',
                                'posts_per_page' => $posts_per_page,
                                'order' => 'ASC',
                                'tax_query' => array(
                                        'taxonomy' => 'testimonial-category',
                                        'field'    => 'slug',
                                        'terms'    => 'residential',
                                        'paged' => $paged
    <?php wp_pagenavi(array( 'query' => $query )); ?>

    Any help from the forum members. Looking forward.. thanks


  2. Lester Chan
    Plugin Author

    Posted 1 year ago #

  3. sydmeeran
    Posted 1 year ago #

    Lester Chan,

    I appreciate your swift reply.

    Yes. I tried with default next & previous post. And it is working only if the " Blog pages show at most " value is same as 'posts_per_page' => $posts_per_page .

    ex: if "Blog pages show at most" value is 5 and my $posts_per_page is 5. Then it is working.

    Basically i have more custom-post type on the site and each post type have different posts per page.

  4. Lester Chan
    Plugin Author

    Posted 1 year ago #

    What I meant was in the same case scenario Residential/Commercial in testimonials, is it working with next/previous posts link?

    I think your paged should not be in the tax_query, but should be at the same level as posts_per_page http://codex.wordpress.org/Class_Reference/WP_Query

  5. sydmeeran
    Posted 1 year ago #

    Yes. The prev/next working with residential/commercial.

    P.S. Yes i changed the code and paged is at the top level. i used it below it for testing it.

    Any clue why i am getting 404.?

  6. Lester Chan
    Plugin Author

    Posted 1 year ago #

    Hmm, might be related to http://wordpress.org/support/topic/pages-toward-the-end-of-pagination-give-404?replies=8

    conflicting hard coded posts_per_page in the query and "Blog pages show at most" in the Reading settings were confusing it. WordPress was supplying enough pages to cater for the Reading settings value of 18 per page and wp-pagenavi was rendering enough links for the posts_per_page value in the query.

  7. sydmeeran
    Posted 1 year ago #

    adding the below code fixes the issue but it modifying the post_per_page globally.

    function my_custom_posts_per_page( $query ) {
    if (!is_admin() && post_type_exists('testimonials') )
            $query->set( 'posts_per_page', 2 );
    add_filter('parse_query', 'my_custom_posts_per_page');
  8. Lester Chan
    Plugin Author

    Posted 1 year ago #

    Wow nice. I like your fix. I didn't thought of that!

  9. cgsdwc
    Posted 11 months ago #

    I cannot get your Page Navi to display properly or at all for tat matter and I need help I had to pay X-cart $180.00 to fix it and now it is not working again, I cannot afford to pay to have this fixed again. I need you help please.

    I have two site that this is installed on and it just doesn't at all on both sites at

    http://www.cheapsalesconsulting.com/blog and http://www.sex-toysonline.com/blog

    Can you help me please, I am not to savvy on PHP and html ..I thought I would just install and it would works.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic


No tags yet.