Custom Post Type and Permalink
July 28th, 2010 by Frank • WordPress News • 8 Comments
Since WordPress 3.0 you can use Custom Post Types and you can define your own types of content - it's more like pages than posts! Thereby you can use automatically the Permalink structure of your WordPress installation. That means, if you create a new post type, you can use Permalinks.
But the Permalinks only work if you recreate the Rewrite Rules of WordPress - that's why many users initially have problems with it. If you create a new post type you probably get a 404 if you open this page because WordPress doesn't know the URL-structure in your Permalinks since you didn't create the Rewrite Rules again.
The easiest way is to safe the Permalink structure in your settings again. Alternatively you can include in your Plugin or Theme the function flush_rewrite_rules(). This enables to create the Rewrite Rules again. Important: Flush rules only on activation or deactivation. Don't do it on any other hook.
Info
- Published in WordPress News
- Tags: PHP, Plugin, WordPress, WP, WP3.0
- Comment feed | Trackback URL
- read: 4707 | today: 108
- leave a Comment



Thanks for the info Frank. I'm going to have to try the custom post types one of these days.
"The easiest way is to safe the Permalink structure in your settings again"
Only visiting the Permalink page in the Admin Settings is enough, it flushes the rewrite rules.
"Alternatively you can include in your Plugin or Theme the function flush_rewrite_rules()."
Not a good idea because 1. It is too heavy to flush the rules each time a page is visited and 2. This may break other plug-ins' permalink structure.
Please flush only after include the new custom post type!
To clarify: Flush rules *only* on activation (and deactivation). Don't do it on any other hook.
Does this apply to custom taxonomies, too? Because I am having trouble with the permalinks of custom category-type taxonomies.
Well, to answer myself here, yes, it does!
I was already giving up. Thank you so much for this timely info.
So to clarify if I wanted to flush after a theme is activated would that be the appropriate place to make the function call?
Thanks!
Can you give us real example custom post type?