Support » Fixing WordPress » WordPress 3.4 and Pagination Custom Post Type Error

  • The problem: After upgrading from 3.3.2 to 3.4.1, pagination broke for category pages (and others). Anything with the structure [category]/page/[page #] returns a 404 error. Reverting back to 3.3.2 removes the error. I have tried a few solutions presented in this forum, including:

    However, nothing has worked so far.

    What I have found out:

    I use NetBeans to debug my site. An example of what I think is happening… for a page that ends as [site]/this_category/page/3, WordPress seems to want to use “3” as the category to query, rather than “this_category”.

    This eventually led me to dig into WordPress’s class-wp.php file. I think the problem is occurring within the parse_request function.

    I have run my site pre (3.3.2) and post (3.4.1) upgrade through my debugger. What I have found is that on line 211 of class-wp.php, is the following line of code:

    $this->matched_rule = $match;

    Below are the results of using [site]/this_category/page/3:

    Version 3.3.2 results in $match == ‘(.+?)/page/?([0-9]{1,})/?$’ and page 3 loads properly.

    Version 3.4.1 results in $match == ‘(.+?)/?$’ and results in a 404 error.

    I am not very good with regular expressions, and I do not know what changes have been made between 3.3.2 and 3.4.1 to result in different regular expression matches for the same URL at this point in the code.

    Any help would be greatly appreciated!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Additional information: I have the following permalink structure:


    I have links to pages that include [site]/[category], and following that [site]/[category]/page/[page #].

    It is the [site]/[category]/page/[page #] links that no longer work. With pretty permalinks turned off, pagination works fine. This is not an issue with my theme, as the same problem happens in twentyeleven.

    It seems that the following rewrite rule is part of wp_rewrite in 3.3.2:

    (.+?)/page/?([0-9]{1,})/?$ => index.php?category_name=$matches[1]&paged=$matches[2]

    This rewrite rule no longer exists after the upgrade to 3.4.1, and is what I believe I need to make my pagination work again.

    How do you add a rewrite rule permanently? I tried editing the ‘rewrite_rules’ option of my options table in the wordpress database… but this simply gets written over the next time any page is loaded. I’ve also experimented with the ‘add_rewrite_rule’ function but have not had any success.

    Any advice, or pointing me in the right direction would be a great help! Thanks!

    Moderator Sergey Biryukov


    WordPress Dev

    Thanks for the report.

    I’ve submitted a patch to resolve this on

    As a workaround, WP No Category Base plugin can be installed to create the missing rewrite rules.

    Thanks for the reply Sergey.

    For the time being, I’ve added the following code to my function.php:

    function yoursite_init() {
      global $wp_rewrite;
    		//add rewrite rule.

    I then load a page, and comment the following line to avoid running flush_rules on every page load:


    Note that I also added an “author” rule which already exists, as just adding the “page” rule was interfering with author pagination… simply changing the order of the rewrite rules seems to have fixed this problem (that is, checking for an “author” rewrite match before the “page” rewrite match).

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘WordPress 3.4 and Pagination Custom Post Type Error’ is closed to new replies.