views:

342

answers:

3

i am looking for a way to get the post_type into a wordpress permalink structure - especially considering custom post_type's defined by my own plugin.

is there an easy way to do that, or do you know any decent documents about wordpress url handling / redirection (codex seems to lack a bit on the rewriting side of things).

+1  A: 

By post_type do you mean category? If so, I think you can do this using the custom permalinks settings in the wordpress admin panel.

%category% is the one you want. Note from the wordpress codex there is a warning about performance if it's at the start of the permalink - I haven't used this, so something you may want to look into:

%category% - A sanitized version of the category name (category slug field on New/Edit Category panel). Nested sub-categories appear as nested directories in the URI. Starting Permalinks with %category% is strongly not recommended for performance reasons.

EDIT - If however, you are looking for post type, as in post / page, then this will be more tricky. It isn't one of the built in structure tags, so you may be looking at having to add this new structure tag, which would be a change to wp-includes\rewrite.php (and reapplying with each new wordpress patch). There may be another way to do it with mod-rewrite, but heading beyond the scope of my knowledge I'm afraid

Kris C
sorry, no, i mean the post_type literally - its a property of the posts table, long time used for posts,pages,attachments and links, but starting with wp 2.9 it became more open for plugin developers via functions like register_post_type
roman
+1  A: 

It seems that if you use any permalink structure besides the default, then you end up getting a permalink structure of /post_type/post_name.

So, if I regsitered the post_type 'video' it would be http://yourdomain.com/video/post_name

If you're using the default permalink, then obviously it doesn't matter because you'll just have ?id=123 or whatever. (Though, you can specify post_type as a query_var, which can be useful in your theme.)

As a sidenote, it seems ridiculously difficult to try and override WP's default URL routing, and you COULD do it by using some of the actions and filters... but the above should work for what you are wanting.

Finster
thnx for the hint with post_type and the default permalink. in spite of that we ended up implementing our own url rewriting which was not that difficult (still havent got the time to write it down as a blog post though)
roman
Good to hear! Would look forward to seeing what you have on wp-rewrite, as it looked really frustrating to set up without having a bunch of convoluted apache rewrites.
Finster
For those that are wanting more info about all of this... I found this post today: http://xplus3.net/2010/05/20/wp3-custom-post-type-permalinks/explains how to customize the post_type slug. Pretty handy.
Finster