[wp-hackers] wp-rewrite

DD32 wordpress at dd32.id.au
Tue Feb 5 08:34:03 GMT 2008

I'm writing up a plugin at present, and i'm wanting to add in a rewrite rule for 

I'd like to map it so that i can catch custom_page_name, and re-map ?hash to the postname (To prevent wp_query having to make 2 requests to the database)

function tp_add_rewrite_rules( $wp_rewrite ) {
    $new_rules = array( "(custom_page_name)" => 'index.php?tp=' . $wp_rewrite->preg_index(1) );
    $wp_rewrite->rules = $wp_rewrite->rules + $new_rules;

Accomplishes the first part of it pretty simply(Note that i've allready added the tp queryvar/etc)

I was pretty sure i did this before:
    $new_rules = array( "(custom_page_name).*hash=(.*?)" => 'index.php?tp=' . $wp_rewrite->preg_index(1) . '&name=' . $wp_rewrite->preg_index(2) );
And it worked... But, I cant seem to get that working again, It simply breazes straight over the rule as the $request according to WP is now simply only "custom_page_name"

Upon looking through the sourcecode to find a better explanation, It seems to me that WP is trimming the query params off when doing the matching.. Yet i swear i managed to redirect ?hash=abc to the pagename yesterday..

Changing the input isnt a go-er as its a pre-made protocol i'm working with, And i'd prefer to prevent WP making a 2nd query to the database..

(Little background, I'm basically using the loop, But its being output in a custom way, and a custom input stream, the hash will allways be the post slug i'm after)

Any thoughts on how i should be going about this? Maybe i should be simply matching it myself using my own regular expression before WP does its wp_rewrite matches somehow?

More information about the wp-hackers mailing list