[wp-hackers] 2 Questions: $_REQUEST equivalent and using GET in mod_rewrite

DD32 wordpress at dd32.id.au
Wed Aug 29 01:06:14 GMT 2007

This seems to come up quite a bit, and its definately challenging for  
people when they first try to use it.
I've recycled some of my own code into a test plugin that shows how to use  
the Rewrite engine a bit better:


By just uploading and activating it, it allows this: (without touching  
anything else in WP, no pages defined etc)

Query vars are Escaped strings though, So this:
Results in this:
Plugin for Artist: Oh\\\\\\\'John
(Why there are so many slashes i'm not sure)

while http://dd32.id.au/artist/Oh"John/
Would be: Plugin for Artist: Oh\"John

> How can I get /artists/x/ to translate to artists.php?id=x or whatever.
By the sounds of it, you've developed the standalone app not quite how  
you'd write a WP plugin.
My suggestion would be to modify the code i've linked to, and instead of  
die(), you'd do something like:

function test_template($arg){
     global $wp_query;
     if( !isset($wp_query->query_vars['artist']) )
         return $arg;
     if( 'index' != $wp_query->query_vars['artist'])
         $_REQUEST['id'] = $wp_query->query_vars['artist'];
     die(); //We dont want WordPress to execute after the scripts run

Theres probably a better hook than template_redirect, but i find it works  
well, its right before any output is started so i find its a good place to  
cut in.

I hope its of use to you and others.


On Wed, 29 Aug 2007 03:01:28 +1000, Alex Andrews <awgandrews at gmail.com>  

>> > More importantly, I want to use mod_rewrite to map onto this plugin. I
>> > know Wordpress can do this, but I am not sure how. Here is the schema
>> > I imagine, artists.php being replaced by the correct wordpress plugin
>> > hookup (some suggestion here might be helpful two)
>> One of my plugins uses the following:
>> function myRewrite($rules)
>>         { $rules['foo'] = 'index.php?pagename=foo'; return $rules; }
>> add_filter('rewrite_rules_array', 'myRewrite');
>> When the plugin is activated, you must visit
>> wp-admin/options-permalinks.php (once is sufficient) to add your slug to
>> WP's ruleset.
>> Then, every request that calls /foo/* in this example, will be handled
>> by the plugin. However, this solution also requires to have a page with
>> the slug "foo". Maybe there's a better solution, but this one works for
>> me.
> It appears that in the Codex there is a description. It seems the
> latter example might suit my needs if adapted, but the problem is
> still input. How can I get /artists/x/ to translate to
> artists.php?id=x or whatever.
> http://codex.wordpress.org/Function_Reference/WP_Rewrite#Example
> Regards
> Alex
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers

Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

More information about the wp-hackers mailing list