[wp-hackers] WP_Rewrite query

Rob powzor at gmail.com
Sat Feb 4 04:44:29 GMT 2006


I'm trying to hook into the rewrite rules, in order to allow /library/ 
to display my-plugin.php?library=true, but I'm running into some problems.

I'm currently modifying the rewrite rules using Ryan's code from the codex:

------------
function nr_mod_rewrite($wp_rewrite) {
   
    $rules = array(
        'library/?' => 'wp-content/plugins/my-plugin.php?library=true'
    );
   
    $wp_rewrite->rules = $rules + $wp_rewrite->rules;
   
}
add_filter('generate_rewrite_rules', 'nr_mod_rewrite');
------------

but it just displays the index page of the site, entries and all. The 
library/? match is certainly working, since going to /blah/ gives a 404, 
but I discovered that the rewrite will only work if you're rewriting to 
index.php; this works, for example:

------------
$rules = array(
        'library/?' => 'index.php?p=1'
);
------------

...displaying the first post in my blog when you visit /library/. I 
thought then that I could just redirect to "index.php?library=true", and 
then hook into init() to check $_GET['library'] and do what I want if it 
was set, but no dice; it never seems to pass the variable in the query 
string, as var_dump()ing $_GET gives an empty array every time.

I'm totally stumped - either this is totally the wrong way to achieve 
what I want to achieve, or I'm just being inordinately stupid. Can 
anyone help? Is there some easier way of redirecting that I'm totally 
missing?


More information about the wp-hackers mailing list