WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] After WP 3.4 Upgrade the pagination setup not working anymore (15 posts)

  1. evo_x
    Member
    Posted 2 years ago #

    After I have upgraded the pagination setup is not working anymore after a certain number of pages, I have tried to change 3 themes and I had the same problem with all.

    I found a solution somewhere here, but it solved the problem only for the blog posts pages index (tags, categories and search still not working)

    After I have added this code to theme functions

    function my_post_queries( $query ) {
      // not an admin page and it is the main query
      if (!is_admin() && $query->is_main_query()){
        if(is_home()){
          $query->set('posts_per_page', 1);
        }
      }
    }
    add_action( 'pre_get_posts', 'my_post_queries' );

    the pagination of the home/blog posts works correctly, but search, category and tags pagination is still does not work after a certain number of pages, what can I do ?

  2. keesiemeijer
    moderator
    Posted 2 years ago #

    Do you want to have 1 post per page on all your site pages?
    Change the "Blog pages show at most" setting on Settings > Reading

    otherwise change this in the function:

    if(is_home()){

    to this

    if(is_home() || is_category() || is_tag() || is_search() ){
  3. evo_x
    Member
    Posted 2 years ago #

    I have Blog pages show at most: 20
    For 3 days I am looking for a solution, but nothing works :(

    you can see here http://paper-backgrounds.com/category/abstract-backgrounds/

    the pagination on this category works until page 7, after that I get 404 and on other categories or tags the pages which work are different.
    on the home page it displays all pages, after I have added the above code with the pre_get_posts.

  4. evo_x
    Member
    Posted 2 years ago #

    I think in one of these two files is the problem.

    Here is blogstyle.php http://pastebin.com/k2tY1PVn
    and defaultindex.php http://pastebin.com/Lkz2Xgf5

  5. chand_4rana
    Member
    Posted 2 years ago #

    Hello,

    I have same problem here , i have query like this

    $post_info = $wpdb->get_results($srch_sql);

    Searching works perfectly and pagination looks fine but when i navigate the next page i m facing 404 page.

    can anybody solve my problem.......?

    Thanks

  6. evo_x
    Member
    Posted 2 years ago #

    It seems that in WP 3.4 has changed the pagination, now everybody is affected, but no one can give a solution

  7. keesiemeijer
    moderator
    Posted 2 years ago #

    It seems that in WP 3.4 has changed the pagination, now everybody is affected, but no one can give a solution

    Or your theme is querying the loop wrong and messing up pagination.

    I'm sorry but your theme has some very complex queries going on, so I don't think I can find a solution for you.

  8. evo_x
    Member
    Posted 2 years ago #

    I have tried other 2 themes and it has the same problem.

  9. chand_4rana
    Member
    Posted 2 years ago #

    please try this in function.php
    it is work for me

    //for pagination 404 error page
    function my_post_queries( $query ) {
    // not an admin page and it is the main query
    if (!is_admin() && $query->is_main_query()){
    if(is_home()){
    global $paged,$exl_posts;
    if(get_option('show_on_front')== 'posts')
    {
    if ( get_query_var('paged') ) $paged = get_query_var('paged');
    if ( get_query_var('page') ) $paged = get_query_var('page');
    }
    else
    {
    if ( $wp_query->query_vars['paged'] ) $paged = $wp_query->query_vars['paged'];
    if ( $wp_query->query_vars['page'] ) $paged = $wp_query->query_vars['page'];
    }
    $arg = array( 'paged' => $paged);
    if(CUSTOM_POST_TYPE1)
    {
    $arg['post_type'] = CUSTOM_POST_TYPE1;
    }
    query_posts($arg);
    }
    }
    }
    add_action( 'pre_get_posts', 'my_post_queries' );

    cheers...

  10. evo_x
    Member
    Posted 2 years ago #

    I added your code instead of mine to functions.php and now the paging does not work even for the home page (which worked before) :( the same thing happpens, after a certain number of pages it returns 404 error.

    so I had to put back my code, to have at least the home blog posts paging :(

  11. evo_x
    Member
    Posted 2 years ago #

    Thanks keesiemeijer, I have added this line
    if(is_home() || is_category() || is_tag() || is_search() ){

    and now it works :)
    sorry, the first time I used your line I put it in a wrong place and it did not work.

    Now this code works for me:

    function my_post_queries( $query ) {
      // not an admin page and it is the main query
      if (!is_admin() && $query->is_main_query()){
        if(is_home() || is_category() || is_tag() || is_search() ){
          $query->set('posts_per_page', 1);
        }
      }
    }
    add_action( 'pre_get_posts', 'my_post_queries' );
  12. jointplan
    Member
    Posted 2 years ago #

    keesiemeijer,

    I've had some success with the code but it has moved the issue slightly (and thanks for the code by the way!)

    Original Symptoms as follow
    1. Each Category archive would show the first page
    2. Moving to /page/2/ on each Categories and it would produce a 404.

    Originally I thought it was a WordPress issue since the website was upgraded to WordPress 3.4 but after extensive analysis, it appears to be the theme.

    Implementing the Code
    It helped in terms of getting past the issue of a 404 on /page/2/ (and thought it had cracked it to be honest) but the site now gets a 404 on any category URL that pass /page/3/

    That is, /page/3/ is working but going to the "previous Page" or "Older Entries" produces a 404 on /page/4/

    This is the code that has helped the most

    function my_post_queries( $query ) {
      if (!is_admin() && $query->is_main_query()){
        if(is_home() || is_category() || is_tag() || is_search() ){
    		$query->set('posts_per_page', 1);
        }
      }
    }
    add_action( 'pre_get_posts', 'my_post_queries' );

    Any advise on the code would be a great help as I have tried near on everything in the WordPress Forum on this issue and various combinations thereof.

    There are no plugins that play with the URL and I've also noticed that this applies to TAGS as well as CATEGORIES.

    This is an example of a category that produced a 404 if you click on the "Older Entries" link and go beyond /page3/

    Many Thanks and hope you're able to assist.

  13. jointplan
    Member
    Posted 2 years ago #

    Forgot to add that I thought it was just a /page/2/ issue but it turns out it's the last page that causes the issue.

    There are a few categories that stop at /page/3/ and cause the 404 as well as another that gets to something like /page/9/ before it produces a 404. (These show up on Google Webmaster Tools

    An infinite loop problem but I've struggled to pinpoint the root cause.

    For reference, this is the blog URL

  14. jointplan
    Member
    Posted 2 years ago #

    Additional to this is the $wp_query which is in blog.php that may help identify the issue rather than adding code to functions.php.

    $numwords = 100;
    
    $temp = $wp_query;
    $wp_query= null;
    $wp_query = new WP_Query();
    $wp_query->query('post_type=post&showposts=5'.'&paged='.$paged);
    
    $ct=0;
    
    while ($wp_query->have_posts()) : $wp_query->the_post();
    
    $ct++;
    	if($ct%2==1)
    		$bg="DAD5D5";
    	else
    		$bg="FFFFFF";
    	$strippedDesc = strip_tags(get_the_content());
    	preg_match("/([\S]+\s*){0,$numwords}/", $strippedDesc, $regs);
    	$shortDesc = trim($regs[0])." [...]";
    		if(trim($regs[0])=="")
    	{
    		$shortDesc = substr($strippedDesc,0,600)." [...]";
    	}
  15. Portoa
    Member
    Posted 1 year ago #

    evo_X first solution combined with keesiemeijer suggestion to change if_home to if(is_home() || is_category() || is_tag() || is_search() ){ has worked really solid for me. I have been at this for over 2 hours. Fixed!!

Topic Closed

This topic has been closed to new replies.

About this Topic