You could add a rewrite rule. Rewrite rules are the regular expressions that WP uses to parse out the query from friendly URLs. But I think this would potentially mess things up. How would WP distinguish between /this-is-a-page/this-is-a-child-page/
and /this-is-a-page/this-is-a-parameter/
?
A better option, I think, would be to hook into the parse_request
action. This gets called after WP loads what it thinks are the query vars, but before it makes the query (and so before it decides that the request should be "not found.") This action hook passes the WP object to your function by reference.
add_action("parse_request", "my_parse_request");
/**
* @param WP $wp
*/
function my_parse_request(&$wp){
echo "<pre>";
var_dump($wp->query_vars);
die();
}
For an existing page server.loc/sample-page/
this outputs:
array(2) {
["page"]=>
string(0) ""
["pagename"]=>
string(11) "sample-page"
}
Adding parameters... server.loc/sample-page/parameter-1/parameter-2/
...
array(2) {
["page"]=>
string(0) ""
["pagename"]=>
string(35) "sample-page/parameter-1/parameter-2"
}
Since $wp
is passed by reference you can change $wp->query_vars
directly, after checking what parts of page_name
are actually pages and storing your parameters for use later.
Note that page
in $wp->query_vars
refers to the page number, if any. All you should touch is pagename
.
The code from which parse_request
is called is in wp-includes/class-wp.php
.