Add Rewrite Rule for custom page

function add_my_rule() {    
    global $wp; 
    $wp->add_query_var('args');   
    $wp->add_query_var('arg_username');
    add_rewrite_rule('writer/([0-9]+)/([^/]*)/page/([0-9]+)','index.php?pagename=writer&args=$matches[1]&arg_username=$matches[2]&paged=$matches[3]','top');
    add_rewrite_rule('writer/([0-9]+)/([^/]*)','index.php?pagename=writer&args=$matches[1]&arg_username=$matches[2]','top');
    /*global $wp_rewrite;
    $wp_rewrite->flush_rules();*/
}
add_action('init', 'add_my_rule');

This should do the trick. One rewriterule for writer/user_id/username (username isn’t used in the rewriterule but is necessarily to make it work. The second rewriterule is the same except that it adds pagination.


EDIT: added arg_username in code above.

Leave a Comment