Question

In functions.php I am adding a rewrite rule for this url:

http://www.myblog.com/?currentpage=1
http://www.myblog.com/?currentpage=2
And so on...

This is the code I use, can u please give me the rewrite rules to transform my urls into pretty ones?

    add_action( 'init', 'wpa5413_init' ); 
    function wpa5413_init() {     
        // Remember to flush the rules once manually after you added this code!     
        add_rewrite_rule(           
            'Please add my rewrite rule',         
            'Please add my rewrite rule',  
            'top' ); 
    }

    add_filter('query_vars', 'wpa3537_query_vars'); 
    function wpa3537_query_vars($query_vars) {     
        $query_vars[] = 'currentpage';     
        return $query_vars;
    } 

Ty!

Was it helpful?

Solution

if you are trying to get

then your function should be

add_action('generate_rewrite_rules', 'currentpage_rewrite_rule_222');

function currentpage_rewrite_rule_222($wp_rewrite){
  $newrules = array();
  $new_rules['currentpage/(\d*)$'] = 'index.php?currentpage=$matches[1]';
  $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}

and just keep your query_vars function the way it is.

 add_filter('query_vars', 'wpa3537_query_vars'); 
    function wpa3537_query_vars($query_vars) {     
        $query_vars[] = 'currentpage';     
        return $query_vars;
    } 
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top