This is my code:
function add_my_rule() {
global $wp;
add_rewrite_rule('(.?.+?)/format(/[0-9]+)?/?$','index.php?pagename=$matches[1]&format=$matches[3]','top');
/*global $wp_rewrite;
$wp_rewrite->flush_rules();*/
}
add_action('init', 'add_my_rule');
function add_custom_page_variables( $public_query_vars ) {
$public_query_vars[] = 'format';
$public_query_vars[] = 'pagename';
return $public_query_vars;
} // End add_custom_page_variables()
add_filter( 'query_vars', 'add_custom_page_variables' );
I do flush the rewrite rules each time the plugin is enabled with
flush_rewrite_rules();
…and the rules seem to be registering fine with WordPress, just not working the way I would like them to.