WordPress 3.1.2 Permalinks Broken

I have a fresh install of WordPress 3.1.2 (not upgraded but installed fresh), containing no plugins whatsoever.

I’m having what seems to be from my googling a fairly common problem, but none of the solutions I can find work for me.

Read More

I have a custom taxonomy and a custom post type running, the code from my functions.php:

register_post_type( 'product', array(
    'labels' => array(
        'name' => __( 'Products' ),
        'singular_name' => __( 'Product'),
        'add_new_item' => __( 'Add New Product'),
        'add_new' => __( 'Add a Product'),
        'edit_item' => __( 'Edit Product'),
        'new_item' => __( 'New Product'),
        'view_item' => __( 'View Product'),
        'search_items' => __( 'Search products' ),
        'not_found' => __( 'No products found' ),
        'not_found_in_trash' => __( 'No products found in Trash' )
    ),
    'public' => true,
    'supports' => array(
        'title',
        'editor'
    ),
    'has_archive' => true,
    'can_export' => true
));

register_taxonomy( 'product_category', 'product', array(
    'hierarchical' => true,
    'labels' => array(
        'name' => 'Product Categories',
        'singular_name' => 'Product Category',
        'search_items' =>  __( 'Search Product Categories' ),
        'all_items' => __( 'All Product Categories' ),
        'parent_item' => __( 'Parent Product Category' ),
        'parent_item_colon' => __( 'Parent Product Category:' ),
        'edit_item' => __( 'Edit Product Category' ), 
        'update_item' => __( 'Update Product Category' ),
        'add_new_item' => __( 'Add New Product Category' ),
        'new_item_name' => __( 'New Product Category Name' ),
        'menu_name' => __( 'Product Categories' ),
    ),
    'public' => true,
    'rewrite' => array(
        'hierarchical' => true
    )
));

The problem is that when I go to a product_category archive page, for example http://example.com/dairy-industry, I get a 404. I have tried about a gajillion fixes, including

  • every combination of rewrite arguments on the register_taxonomy code
  • re-saving permalinks
  • turning permalinks off, saving, then turning them on again
  • the above, but first deleting the .htaccess file from the server
  • the above, but first deleting the rewrite_rules option from the wp_options table
  • having the category base and tag base option set (and blank)

I also do not have $wp_rewrite->flush_rules() anywhere in my theme.

The most frustrating thing is that at various times throughout my fixes, and with no pattern I can identify, the custom taxonomy archive pages will start working again, but the regular pages will start giving me 404s instead. They never work at the same time, and I can’t figure out which steps will reproducibly make one or the other work. It seems to be totally random.

For a further bit of interestingness, when the custom taxonomy archive pages are not working, one of them (dairy-industry) redirects to the slug of a similarly-named but different (2011/04/dairy-industry-products) post before giving me a 404.

I’m happy to share any code that may be helpful, just ask.

Can anyone help me figure out this perplexing conundrum?

Related posts

Leave a Reply

4 comments

  1. I’ve had some issues with this before. I found that if you have a custom post type with the same name as one of your page slugs, it can cause huge issues! This may be something you need to consider.

    I now use a plugin to create my custom post types, as it has built in fields for the url structure. This plugin is called CMS Press.

  2. I have been experiencing this problem which only appeared after upgrading to 3.1.2 from 3.1 (we skipped 3.1.1). I get 404 response for custom post types and anywhere that a custom rewrite rule has been applied (e.g. custom feed links).

    I managed to get it working reasonably well with this plugin:

    http://wordpress.org/extend/plugins/wcs-custom-permalinks-hotfix/

    However I still get these pages 404’ing every now and then – I suspect when a new post is added. When that happens I can get them working again by going to the permalink settings page and simply hitting save.

    Be sure to check your htaccess rules – the website for the plugin has a lot of information and recommended htaccess rules for single and multisite setups:

    http://wpcodesnippets.info/blog/wcs-custom-permalinks-hotfix.html

  3. When i first encountered this 404 issue with permalinks, I was frantic. It impacted all of my own sites and several that I manage. Hundreds of folks used a hotfix function that I’d coded … and then responding to various special cases from users … we perfected it to the plugin that you mention.

    The original article is here:
    http://wpcodesnippets.info/blog/how-to-fix-the-wp-3-1-custom-permalinks-bug.html

    It is my estimation that this bug has impacted thousands of WP sites. But, the official developers have declined to address it in any subsequent updates. Fortunately, the plugin should work in perpetuity.

    Regarding your occasional 404’s for new posts, I’m particularly curious if you discover the culprit. Here’s one thing to try. As soon as this happens with a new post, pull your site up in a browser that you don’t normally use … and see if you can click a link to the new post from there.

    Certainly, older plugins that modify or access the permalink structure will need minor mods until WP decides to address the issue.

    Anyway, I’m glad the plugin has helped.