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

Mike Schinkel mikeschinkel at newclarity.net
Sun Apr 18 17:37:22 UTC 2010

On Apr 18, 2010, at 6:49 AM, scribu wrote:
> On Sun, Apr 18, 2010 at 1:37 PM, Mike Schinkel
> <mikeschinkel at newclarity.net>wrote:
>>       $pages = get_pages();
>>       foreach ( $pages as $page )
>> $wp_rewrite->add_rule("$page->post_name/?","index.php?post_type=page&p={$page->ID}",'top');
>> Only problem is, in either case, now it calls single_template instead of
>> page_template.  Go figure.
> You should use *?page_id=* instead of *post_type=page&p=*

Awesome, that did it. Thanks!  

But unfortunately it's still not 100% complete.  This is the code that works thus far:

		global $wp,$wp_rewrite;
		$wp_rewrite->add_rewrite_tag('%financial-term%', '([^/]+)','financial-term=');
		$wp_rewrite->add_permastruct('financial-term', '%financial-term%');
		$pages = get_pages();
		foreach ( $pages as $page ) {

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.  

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?


More information about the wp-hackers mailing list