I am writing a plugin, which routes URLs to a custom format.
Quite simply put I want to get rewrite rules for a given path, can I do this?
so for example, I need a function as follows:
$path = 'team/john-smith';
$rules = get_rules($path)
$rules is now something like
index.php?team=john-smith&post_type=team&name=john-smith;
or alternatively, the actual rewrite rules array (and I can build the string myself…)
array("team" => "john-smith", "post_type" => "team", "name"=> "john-smith");
Have you looked at this function in includes/rewrite.php:
function url_to_postid($url)
My guess is that to get the actual rewrite rules, you would use:
Or call
page_rewrite_rules()
. There’s a few interesting looking bits of code in that file.