[wp-hackers] Custom permalinks with the Rewrite API

Eric Martin emartin24 at gmail.com
Sat Oct 10 14:00:52 UTC 2009

On Oct 9, 9:15 am, Austin Matzko <if.webs... at gmail.com> wrote:
> On Fri, Oct 9, 2009 at 10:48 AM, Eric Martin <emarti... at gmail.com> wrote:
> > I want to be able to allow users to custom sort a group of posts by
> > adding a custom rewrite rule. I'm thinking of the following structure:
> > /some-slug/sort/title:desc/
> > /some-slug/sort/date:desc/
> > /some-slug/sort/downloads:desc/


> If "some-slug" is for pages, why don't you attach a callback to the
> "page_rewrite_rules" filter ("post_rewrite_rules" for posts)?  Then
> copy the array of rules passed to the callback, and loop through that
> copy, modifying each key and value to work with your rewrite scheme.
> Then prepend the modified array to the current ones and return.
> Or create the modified version by temporarily modifying
> $wp_rewrite->page_structure, then calling
> $wp_rewrite->page_rewrite_rules() to generate the modified version.
> However, I don't think that would help with something like
> > /some-slug/page/2/sort/title:desc/

Thanks for the suggestions Austin. I was hoping to be able to use the
rewrite api w/o having to use callbacks to manually parse the rules.
However, if that isn't possible, I'll be sure to try these out ;)


More information about the wp-hackers mailing list