[wp-hackers] Need Custom Post Type Rewrite Help, Please

scribu scribu at gmail.com
Sun Apr 18 19:45:42 UTC 2010

On Sun, Apr 18, 2010 at 8:37 PM, Mike Schinkel
<mikeschinkel at newclarity.net>wrote:

> Unfortunately I'm finding that get_permalink() returns '
> example.com/financial-term/term-name/' (which generates a 404) instead of
> 'example.com/term-name/' which serves as I want it to.  I can of course
> hook 'post_link' and manipulate the link but it's like I shouldn't have to
> do it that way and thus am doing something wrong.

Yeah, unfortunately the rewrite rule generating code isn't connected with
the link generating code.

OTOH, looking just now at the definition of register_post_type() it seems to
> give no other option than something like '%post_type%/post-name'.  Any
> ideas, or is this just where a new filter is needed?

Not necessarily a filter... the 'rewrite' argument should accept a permalink
structure, instead of just true/false, but that's something for 3.1 maybe.

> wbt_post_type_link',10,3);
> function wbt_post_type_link($link, $id, $leavename) {
>        if (strpos($link,'financial-terms/')!==false)
>                $link = str_replace('financial-terms/','',$link);
>        return $link;
> }

I would replace

if (strpos($link,'financial-terms/')!==false)


if ( 'financial-term' == get_post_type($id) )


More information about the wp-hackers mailing list