[wp-hackers] Update Plugin Rewrite Rules

Jamie Talbot wphackers at jamietalbot.com
Thu Feb 2 17:49:49 GMT 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Mr.Brown wrote:
> I added the rules by a plugin (I'm not sure I understood the mechanism):
> <?php
> function RTS_pics_rewrite($rewrite) {
> global $wp_rewrite;
> $keytag_token = '%pics%';
> $wp_rewrite->add_rewrite_tag($keytag_token, '(.+)', album=');
> $keywords_structure = $wp_rewrite->root . "pics/$keytag_token";
> $keywords_rewrite = $wp_rewrite->generate_rewrite_rules($keywords_structure);
> return ( $rewrite + $keywords_rewrite );
> }
> add_filter ('rewrite_rules_array', 'RTS_pics_rewrite');
> ?>
> I tried also with
> add_filter ('page_rewrite_rules', 'RTS_pics_rewrite'); and
> add_filter ('root_rewrite_rules', 'RTS_pics_rewrite');

add_filter ('rewrite_rules_array', 'RTS_pics_rewrite');

is correct.

> 
> Any ideas?

have you also added the ability to recognise the %pics% tag you just added, using the query_vars
filter?  You also might want to not use + to join your two arrays together.  Seeing as the rewrite
rules array can be passed by reference you can just add it that way.  Try this and see if it works:

add_filter('query_vars', 'RTS_query_vars');
add_filter('rewrite_rules_array', 'RTS_pics_rewrite');

// Define the language query variable.
function RTS_query_vars($vars)
{
	$vars[] = 'album';
	return $vars;
}

function RTS_pics_rewrite(& $rewrite)
{
	$keytag_token = '%pics%';
	$wp_rewrite->add_rewrite_tag($keytag_token, '(.+)', album=');
	$keywords_structure = $wp_rewrite->root . "pics/$keytag_token";
	$rewrite[] = $wp_rewrite->generate_rewrite_rules($keywords_structure);
}

Hope this helps, or at least gives you a starting point,

Cheers,

Jamie.

- --
http://jamietalbot.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFD4kY9rovxfShShFARArdMAJ99B+P68knvMgCUk2zLB4VwDifMEwCbBt0E
cCIS9Si7rSto/HWkFwZhNS0=
=5I1y
-----END PGP SIGNATURE-----


More information about the wp-hackers mailing list