Support » Fixing WordPress » Pages don’t work with custom permalinks and categories

  • Resolved Jeff Sherk


    My permalink is set to Custom: /%category%/%post_id%, using WP 2.7.1 with the WordPress Default theme.

    The problem occurs when you have several pages of posts. The first page will display fine, but if you try to go to another page (clicking on Older Entrie) you get a 404 error.

    When I go to a category page (let’s call it ‘stuff’) like it correctly shows the posts for the first page of the category, and if you hover over the Older Entries links is says
    but if you click on this link, you get a 404 Error, and you cannot get to the other pages.

    In the particular case above, $query_string contains ‘category_name’=’stuff/page’ and also contains ‘p’=’2’. The plugin below removes the ‘/page’ from the ‘category_name’, unsets the ‘p’ variable, and sets ‘paged’=’2’. This appears to solve my problem.

    I initially noticed the problem while trying to use the wp-pagenavi plugin, but the problem even existed in the default theme with the plugin deactiviated, so it must a wordpress bug. The above solution solved my problem with the default them and also works with wp-pagenavi.


    Plugin Name: Fix Paging in Category Listings
    Plugin URI:
    Description: Fixes a bug where next/previous page links are broken in category listings
    Version: 0.6
    Author: Doug Smith (modified by Jeff Sherk)
    Author URI:
    Modified on March 23, 2009 by Jeff Sherk for WordPress 2.7.1
    Based on original plugin info listed below:
    Plugin Name:  Fix Paging in Category Listings
    Plugin URI:
    Description: Fixes a bug where next/previous links are broken in category by year/month listings
    Version: 0.5
    Author: Doug Smith
    Author URI:
    Copyright 2007  Doug Smith  (email:
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    GNU General Public License for more details.
     * Function to fix problem where next/previous buttons are broken on list
     * of posts in a category when the custom permalink string is:
     * /%category%/%year%/%monthnum%/%postname%/
     * The problem is that with a url like this:
     * /category/2007/10/page/2
     * the 'page' looks like a post name, not the keyword "page"
     * MODIFIED ON March 23, 2009 by Jeff Sherk
     *  Permalink structure was /%category%/%post_id% which looked like
     *  When attempting to go to another page, it looked like this
     *  but would generate a 404 error .
     *  This modification takes $query_string['category_name'] and chops the '/page'
     *  off the end. It also takes $query_string['paged'] and sets it equal to
     *  $query_string['p'], and then unsets $query_string['p'].
     *  'p' is not needed, but 'paged' is needed in order to make it work correctly
    function fix_page_in_category_from_query_string($query_string) { 
        //Check to see if the 'p' and 'category_name' are set in $query_string
        if ( isset($query_string['category_name']) &&  isset($query_string['p']) ) {
          $category_name = $query_string['category_name'];
          $category_len = strlen($category_name); 
          //Check to see if the 'category_name' has '/page' on the end of it
          if (substr($category_name, $category_len-5,5) == '/page') {
            //Remove '/page' from the end of 'category_name'
            $query_string['category_name'] = substr($query_string['category_name'],0,$category_len-5);
            //Set 'paged' equal to the page you want to go to
            $query_string['paged'] = $query_string['p'];
            //Unset 'p' since we don't need it anymore because we set 'paged' instead
        return $query_string;
    add_filter('request', 'fix_page_in_category_from_query_string');
Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi Jeff,

    I have the same problem here (as do others as far as I can see). I installed your plugin, but it does not resolve the issue. I still see


    One the “Older Posts” / “Newer Posts” from the /news/ page which returns 404 errors.

    All other links work fine. I’m using /%category%/%postname%/ for my permalink.

    Any suggestions?


    I’m assuming you ACTIVATED the plugin as well?

    I am honestly not very well versed in WP code or plugins… I had a problem, and was able to find the above fix for it… sorry, but I do not have any suggestions for why it does not work for you.



    Works for me on WordPress 2.8.2


Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Pages don’t work with custom permalinks and categories’ is closed to new replies.