[wp-hackers] $wp_rewrite->add_permstruct() vs. add_rewrite_rule()

Otto otto at ottodestruct.com
Tue Dec 8 16:10:01 UTC 2009

A "permastruct" is a permalink structure as defined by some group of
rewrite tags. So /bob/%bob% would be a permastruct, if "bob" was a
valid rewrite tag.

What's a rewrite tag? That's a variable tag surrounded by % marks.
Just like you can use in the Permalink settings. Like %month% and
%day% and %postname% and so forth. A rewrite tag, once it's parsed out
of the URL, gets turned into some variable in the main $wp_query

Adding a permastruct does (eventually) add a rewrite rule, internally.
If I were to add the permastruct of /wacky/%post_id% , then a URL of
/wacky/4 would bring up the single post with ID #4.

You can add your own rewrite tags with add_rewrite_tag, but custom
tags don't generally do anything unless you add something else to read
and use their values.

Using add_rewrite_rule directly, on the other hand, is a bit more
manual. It just defines a conversion method between a URL and another
URL. That "other" URL is very arbitrary, you can define variables
however you wish.

That help?


On Mon, Dec 7, 2009 at 11:50 PM, Mike Schinkel
<mikeschinkel at newclarity.net> wrote:
> Hi all:
> Okay you WP_Rewrite() gurus, now's your time to shine.
> So I've been trying to figure out $wp_rewrite->add_permstruct() vs. add_rewrite_rule() for the past several days. I've been able to get the former to work but not the latter.  I'm trying to figure out when we would use one and when we would use the other?
> It *seems* like using add_permastruct() can get you support or things like custom single_template and that add_rewrite_rule() would require use of template_redirect, but I can't be 100% sure?
> Can anyone shed some light on these two?  Google has not been my friend in the case of these two functions and how to best use them.
> -Mike
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers

More information about the wp-hackers mailing list