Viewing 8 replies - 1 through 8 (of 8 total)
  • I just had this same problem begin happening today. At first I thought it was caused by a plugin, but then it happened after I removed that. I can’t tell what’s triggering it.

    Any ideas?

    Thread Starter powerhomebiz

    (@powerhomebiz)

    I got the problem fixed by using the code below for URL rewrite and putting it in functions.php. Thanks to another WordPress user who contacted me directly

    add_action('init','yoursite_init');
    function yoursite_init() {
      global $wp_rewrite;
    		//add rewrite rule.
                    add_rewrite_rule("author/([^/]+)/page/?([0-9]{1,})/?$",'index.php?author_name=$matches[1]&paged=$matches[2]','top');
                    add_rewrite_rule("(.+?)/page/?([0-9]{1,})/?$",'index.php?category_name=$matches[1]&paged=$matches[2]','top');
                    $wp_rewrite->flush_rules(false);
    }

    perfect, exactly what I needed. Bless you.

    I have the same problem here and this code didn’t worked for me.

    powerhomebiz, do you mind to share the code you’re using for your website pagination?

    I’ve got this one:

    <?php 	
    
    //The Query
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    
    $category_id = get_cat_id( single_cat_title("",false) );
    
    // Nova query para pegar todos os Projetos.
    $new_query = new WP_Query();
    $new_query->query('showposts=2&cat='.$category_id.'&paged='.$paged );
    
    $contador = 0;
    
    //The Loop
    if ($new_query->have_posts()) : while ($new_query->have_posts()) : $new_query->the_post();	
    
        CONTENT...			
    
    endwhile; 
    
    if($new_query->max_num_pages>1){ ?>
    
    	<div id="paginationWrapper">
    <?php
    	if ($paged > 1) { ?>
        	<a class="pagePrev" href="<? echo site_url('/') ?>videos/page/<?php echo ($paged -1); //prev link ?>"><<</a>
    <?php }
    
    	echo '<div class="pagination"><span class="pgnTitle">'. __('PáGINA').'</span> <span class="pgnPage">0'. $paged .'</span></div>';
    
        if($paged < $new_query->max_num_pages){ ?>
            <a class="pageNext" href="<? echo site_url('/') ?>videos/page/<?php echo ($paged + 1); //next link ?>">>></a>
        <?php } ?>
        </div>
    <?php } 
    
    endif; ?>

    The fix posted by powerhomebiz also worked for me.

    Running WP 3.4.1

    My default category was paging just fine, but my additional categories would not load anything past page 1.

    I had tried reinstalling 3.4, and rolling back to 3.3 with no luck. Applying the fix mentioned by powerhomebiz to the functions.php file in my theme folder seems to have resolved the issue.

    Moderator keesiemeijer

    (@keesiemeijer)

    The solution from powerhomebiz is flushing the rewrite rules on the ‘init’ hook. This is not recommended because it is an expensive operation.
    https://codex.www.ads-software.com/Function_Reference/flush_rewrite_rules

    Try removing this line after you have pagination working and see if it still works:

    $wp_rewrite->flush_rules(false);

    Another way to get pagination working on category pages is by not using a query_post or a new WP_Query() in the category template file. But by putting this in your theme’s functions.php:

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

    This example sets the posts per page to 5 on all category pages. If you only want this on a specific category change the is_category() conditional tag in the code

    https://developer.wordpress.com/2012/05/14/querying-posts-without-query_posts/
    https://www.billerickson.net/customize-the-wordpress-query/

    Many many thanks powerhomebiz,

    The fix works!! I can put “Category pagination fix” plugin to the trash. It didn’t work on last version 3.4.1.

    add_rewrite_rule(“(.+?)/page/?([0-9]{1,})/?$”,’index.php?category_name=$matches[1]&paged=$matches[2]’,’top’);

    Best regards,
    Sylvain

    Eventually, that’s the 3.4.1 causes the bug I had.

    The 3.4.2 version has fixed itself the rewrite rule bug.

    Regards,
    Sylvain

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Category Pagination broke with WordPress 3.4’ is closed to new replies.