WordPress Custom Post Type Permalinks Broken

I was having a big problem with wordpress’ custom post types (register_post_type) and 404 / not found errors when using custom permalinks (taxonomies). It was quite annoying until I found the problem: it seemed the taxonomy cache needs to be flushed out after you add a new post type. Here are notes on how to fix this problem:

“Been having this issue with custom post types in general. I seem to have a fix that I’m hoping will work for you guys. It’s a two parter.

After you’ve made your changes to functions.php or wherever you’re adding/editing post types or taxonomies,

1) go into the wp_options table in your database and clear out the option_value field for option_name rewrite_rules .

2) Then go back into your WordPress admin > Settings > Permalkinks and click the save button.

This should reset your rewrite rules to reflect your new rewrite settings for your taxonomy.”

“If you are writing a plug-in, add:

add_action('admin_init', 'flush_rewrite_rules');

your rewrite rules will be flushed when you activate the plug-in then.”

^ PS: Don’t leave that enabled b/c it has quite a profound effect on the number of queries needed to load a page each time.

Thanks @stunnaboi and @tombrink via wp

Final note: If your permalinks are still having issues after trying this, disable the plugins you have running, try this again, and see if that works. If so, one of your plugins is causing trouble with your rewrite rules!

Related Posts:

  • No Related Posts
This entry was posted in Tech Tips, Web Development and tagged . Bookmark the permalink.

7 Responses to WordPress Custom Post Type Permalinks Broken

  1. George Gomes says:

    You saved me!I deleted the content “rewrite_rules” and updated the “permalinks” in the settings.

  2. chris mcclanahan says:

    Thank you so much! Also, Corey’s comment worked like a charm: “add add_action(‘admin_init’, ‘flush_rewrite_rules’); to my functions.php file temporarily to flush the rewrite rules, “

  3. gustavo says:

    This worked for me just by simply re saving my permalink structure. thank you very much, I had a feeling this was going to be a long trip, yet it was short lived thanks to this post! Thanks again!

  4. Shoeb Mohammad says:

    Thanks a million! Just adding action resolved the issue! Good job!

  5. Pingback: links for 2011-05-08 | Ronaldo Richieri

  6. Luke Hollins says:

    A silly way to cause the update if you don’t have any entry for tags or category in permalinks. Put in “category” or “tag” for one of them (those are the defaults) , save then take it out and save.

  7. Corey says:

    Thanks, this worked like a charm. I was actually able to just add add_action('admin_init', 'flush_rewrite_rules'); to my functions.php file temporarily to flush the rewrite rules, then re-save my Permalink structure.

Leave a Reply

Your email address will not be published. Required fields are marked *