你可能会滥用add_rewrite_endpoint
为此,具体取决于您想要做什么。
一些示例:
// add an endpoint
// http:domain.com/role/
// http:domain.com/role/foo/
function wpa_add_role_endpoint(){
add_rewrite_endpoint( \'role\', EP_ALL );
}
add_action( \'init\', \'wpa_add_role_endpoint\' );
// check if a role parameter exists, like:
// http:domain.com/role/foo/
function wpa_role_query( $query ){
if( $query->get(\'role\') ){
echo $query->get(\'role\'); // echoes \'foo\'
// modify the query $query->set( \'somevar\', \'someval\' );
}
}
add_action( \'pre_get_posts\', \'wpa_role_query\' );
// check if role is in query vars array, like:
// http:domain.com/role/
function wpa_role_parse( $query ){
if( array_key_exists( \'role\', $query->query_vars ) )
die(\'role query\');
}
add_action( \'parse_request\', \'wpa_role_parse\' );