• Resolved Ansif

    (@ansif)


    Hi,

    I’ve faced pagination problem in my theme after updating WordPress 4.4 version.

    Here is my code :

    // Pagination $paged
    global $post, $paged;
    if( get_query_var( 'paged' ) )
      $my_page = get_query_var( 'paged' );
    else {
      if( get_query_var( 'page' ) )
        $my_page = get_query_var( 'page' );
      else
        $my_page = 1;
      set_query_var( 'paged', $my_page );
      $paged = $my_page;
    }
    
    // Query
    $args = array(
      'paged' => esc_attr($my_page),
      'post_type' => 'post',
      'order' => $blog_order,
      'orderby' => $blog_orderby,
      'offset' => (int)$blog_offset
    );
    $wpbp = new WP_Query( $args );
    
    // Output
    if ($wpbp->have_posts()) : while ($wpbp->have_posts()) : $wpbp->the_post();
    	get_template_part( 'content', get_post_format() );
            echo my_theme_paging_nav();
    endwhile;
    else :
             get_template_part( 'content', 'none' );
    endif;

    And my_theme_paging_nav() function at functions.php file.

    if ( ! function_exists( 'my_theme_paging_nav' ) ) {
    function my_theme_paging_nav() {
    global $wp_query;
    	$big = 999999999;
    	if($wp_query->max_num_pages == '1' ) {
    	} else {
    		echo "";
    	}
    	echo paginate_links( array(
    		'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
    		'format' => '?paged=%#%',
    		'prev_text' => __( 'OLDER POSTS', 'text-domain' ),
    		'next_text' => __( 'NEWER POSTS', 'text-domain' ),
    		'current' => max( 1, get_query_var('paged') ),
    		'total' => $wp_query->max_num_pages,
    		'type' => 'list'
    	));
    	if($wp_query->max_num_pages == '1' ) {
    	} else {
    		echo "";
    	}
    }
    }

    Can you please let me know the changes in WordPress 4.4 from this code?

    Thanks! 🙂

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter Ansif

    (@ansif)

    For your reference :
    When i remove the query, the WordPress itself pagination working fine!

    Like, this :

    if ($wpbp->have_posts()) : while ($wpbp->have_posts()) : $wpbp->the_post();

    to

    if (have_posts()) : while (have_posts()) : the_post();

    So, the problem is within :

    $args = array(
      'paged' => esc_attr($my_page),
      'post_type' => 'post',
      'order' => $blog_order,
      'orderby' => $blog_orderby,
      'offset' => (int)$blog_offset
    );
    $wpbp = new WP_Query( $args );

    Can you please let me know, how can i handle this query?

    Hello,
    This part is causing the issue:

    'offset' => (int)$blog_offset

    Please check if your offset value is correct when using pagination. You need to calculate offset value for each page or set it to empty string when it’s not set:

    'offset' => (!(int)$blog_offset ? "" : (int)$blog_offset)

    Thread Starter Ansif

    (@ansif)

    Cool! 🙂

    Issue fixed! You’re Awesome! 🙂

    Great! Good to hear! 😉

    I am also having issues with Post_Types that have been working all along until something in 4.4 caused it to wreck

    thank you QuanticaLabs!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Pagination not working after updating WordPress 4.4?’ is closed to new replies.