Tag Archive: register_post_type

Understanding Rewrite Tags, or, Custom Permalinks for Custom Post Types in WordPress 3.0+, Part 2

You may recall my ancient post about customizing your custom post type permalinks. When I wrote that, I was still stumbling somewhat blindly through WordPress’s rewrite API. After hacking a little more with it, I think I finally understand what I’m doing enough to write a little more confidently. Continue reading

Excerpts for WordPress Pages

WordPress lets you create excerpts for Posts, but not for Pages. Generally, that makes good sense. If you need excerpts for pages, though, it’s pretty simple to add.

function my_init() {
  add_post_type_support('page', array('excerpt'));
}
add_action('init', 'my_init');

That’s all there is to it. Works with WordPress 3.0+.

Update 2010-10-01: Hey, look, I made it into a plugin.

Archives for Custom Post Types in WordPress

When you create a new post type in WordPress using register_post_type(), WordPress does not automatically create a page for listing the archives of that post type. It’s possible to create one, though, without too much hassle.

For example, you can create an post type called article, and set the permalink for that post type to articles (i.e., an article will have a URL like http://example.com/articles/my-article-title).

Where do you go for a list of all articles, though? You might assume http://example.com/articles/, but you would be assuming erroneously. You could create a page with the slug articles and use a custom template for that page, but that doesn’t work with paging (e.g., http://example.com/articles/page/2/).

Instead, you need to fiddle with WordPress’s rewrite rules. (And thanks to Andrew Wilson for helping me understand this.)
Continue reading

Custom Permalinks for Custom Post Types in WordPress 3.0+

Update 2010-10-04: See Understanding Rewrite Tags for a somewhat more helpful treatment of the subject.

I’ve been playing around with WordPress 3.0 to create a bug/issue-tracking plugin (i.e., using WP to track bugs, not to track WP bugs (although it could conceivably do that)). More details about the plugin will be forthcoming, but now is as good a time as any to share the solution to one problem I came across.

Creating New Post Types and Taxonomies

When you create a new post type, you use the register_post_type function. When you create a new post type through that function, WP creates a new rewrite rule base on the name you give the post type. In my case, I’ve created an issue post type, so all issues, by default, will have the permalink /issue/%issue%/ (where %issue% is replaced with the post slug). Using the rewrite argument to register_post_type, you can change the beginning of the permalink to something different (e.g., /bugs/%issue%/) should you so desire.
Continue reading