WordPress.org

Ready to get started?Download WordPress

Forums

WordPress 3.4 and Pagination Custom Post Type Error (4 posts)

  1. s_zawil
    Member
    Posted 2 years ago #

    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:

    http://wordpress.org/support/topic/wordpress-34-broke-my-paginaton-setup

    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!

  2. s_zawil
    Member
    Posted 2 years ago #

    Additional information: I have the following permalink structure:

    /%category%/%year%/%monthnum%/%day%/%postname%/

    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!

  3. Sergey Biryukov
    WordPress Dev
    Posted 2 years ago #

    Thanks for the report.

    I've submitted a patch to resolve this on http://core.trac.wordpress.org/ticket/21209.

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

  4. s_zawil
    Member
    Posted 2 years ago #

    Thanks for the reply Sergey.

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

    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);
    }

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

    add_action('init','yoursite_init');

    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).

Topic Closed

This topic has been closed to new replies.

About this Topic