Support » Fixing WordPress » Custom permalinks failing on 3.7

  • Resolved revmitcz


    After upgrading to WP 3.7, my custom permalinks (defined in my functions.php file) ceased to work. Downgrading to 3.6.1 solved the problem.

    I did the usual troubleshooting : disabled all plugins, refreshed the “Settings > Permalinks” page, clicked “Save Settings” on the “Settings > Permalinks” page, re-uploading my theme’s functions.php file. Nothing except downgrading worked.

    For reference, here’s the relevant section in my functions.php file :

    add_filter('generate_rewrite_rules', 'rp_rewrite_rules');
    function rp_rewrite_rules($wp_rewrite) {
        $newRules  = array();
    		$newRules['podcasts/(.*)/page/?([0-9]{1,})/?'] = 'index.php?category_name=$matches[1]&post_type=podcast&paged=$matches[2]';
    		$newRules['podcasts/(.*)/?'] = 'index.php?category_name=$matches[1]&post_type=podcast';
    		$wp_rewrite->rules = $newRules + $wp_rewrite->rules;

    The rules do the following : -> shows all posts with post type “podcast” -> shows posts of post type “podcast” from the “podcast-name” category -> shows the 2nd page of results for posts of post type “podcast” for the “podcast-name” category

    Not sure what to do from here except avoid upgrading until I’ve seen other users with similar problems report that the issue is fixed.

Viewing 15 replies - 1 through 15 (of 15 total)
  • Go to paramlink page from WordPress’s menu Settings->paramlinks and update the settings (don’t need to change any settings) by clicking save changes (or maybe you don’t need to update the settings, only visiting the paramlinks page is enough) and then try to view your custom posts. It’ll show up.

    I solved it this way.

    I tried that already, and mentioned having tried it in my initial post. I guess I’ll upgrade again and try it again, in case there was something funky the first time.

    Tried it again, same result.

    To clarify – I’m not trying to access a single post, but an archive of posts. I have a custom post type called “podcast”, so visiting shows all posts of type “podcast” within the category “category-name”.

    Individual posts using the link structure /podcast/full-post-title work just fine.

    I realize I’m using a very customized and uncommon setup here, I just wonder if anyone else has had this issue and/or if there’s a fix (beyond “downgrade to 3.6.1 for the timebeing”).

    I’m making a little bit of progress. I did print_r on the wp_query on my archive.php page, and it shows that the category name AND post-type are indeed being passed through. Now I just can’t figure out why it’s using archive.php instead of category.php

    revmitcz, I had the same issue with Custom Post Types and media attachments. Visiting a custom post would bring up the attachment.php page and it was because the Post title and Attachment had the same name. I renamed the attachment and then I could view my custom post properly.

    revmitcz, I have the same problem but haven’t found a solution yet, will post if I do, hopefully someone will solve it soon.

    Well, I’m relieved to know I’m not the only one with this issue. But, I’m also worried that if I had been auto-upgraded to 3.7 (as will apparently be the case from 3.7 onward), my site would’ve broken pretty badly.

    Hmm. I’ve been hit with this on some of my custom post types (not on others, though).

    Here’s what I’ve been able to determine:

    They’ll display again if I use this setting in the register_post_type function:

    'hierarchical' => false,

    Then I re-save the permalinks page (flushing the rewrite rules).

    I also dumped the rewrite rules in both 3.6.1 and 3.7.1 and found some differences. I have this rule in my 3.6.1 dump:

        string(68) "index.php?post_type=hdnet_programs&name=$matches[1]&page=$matches[2]"

    Based on a process of elimination, I believe that the corresponding rule in 3.7.1 is this:

        string(72) "index.php?post_type=hdnet_programs&pagename=$matches[1]&page=$matches[2]"

    Hope this helps…


    I had this problem, too. I solved it by again disabling all plugins, re-updating, and saving the updated permalink structure. This broke Bullet Proof Security, which needed to be reactivated. After re-activation, everything is back to normal.

    We solved it by changing
    'hierarchical' => true,
    'hierarchical' => false,
    Don’t know why having it set to true would cause the break of the permalink structure, this may be a core bug.

    Same thing was happening to one of my 3.7.1 sites.

    'hierarchical' => false was the fix after resaving my permalink structure.

    I was looking for this issue under just 404 permalink custom post type and it didn’t come up. However once I added 3.7.1 then I saw others with issues.

    Thank you for helping us solve this bug.

    Just tried upgrading to 3.7.1, and noticed I’d not defined 'hierarchical' => false in my theme’s functions.php file (thereby using the default “false”).

    Went ahead and added that in, saved my permalinks in the admin and.. same issue. My permalinks are going to what is basically my “custom post type = podcast” overview page. The page’s TITLE, interestingly enough, displays the category correctly. So, perhaps it’s something on the page itself where I’m defining which PHP file to use.

    Okay, after doing a print_r of $wp_query on the page itself (which is archive.php), all the info appears correct. That is to say – it’s printing out exactly the same information that it would if it were on the page for that category (12 posts from that category, along with associated data).

    For some reason, however, WP is redirecting to the archive.php page and NOT the category.php page.

    Any ideas? Right now, I’m thinking I should play around with some of the options I set in my functions.php file where I define the custom post type.

    Okay, it turns out I was doing a lot more custom routing of the permalinks than I thought. It’s not pretty, but it works now.

    It was expecting a URL like :
    but, I’d set it up to use :

    I’m sure I set it up a little weird, cause I share category names across podcast post types AND blog posts, but I wrote a little permalink redirect in the functions.php file so now both methods work fine.

    Thanks for your help, everyone!

    For what it’s worth, though this is marked as resolved, I did find another interesting fact: ‘hierarchical’ can still be set to true if ‘query_var’ is set to true as well when you set up the custom post type.

    This actually makes more sense to me, I think, if I read the documentation correctly.


Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Custom permalinks failing on 3.7’ is closed to new replies.