I want the WooCommerce way to create new rules for permalinks. I have checked WooCommerce core files and found that WooCommerce is using this filter for saving the rule in database. My current url is /?page=mpProfile. I have var dumped get_query_var('pagename'); on hit page, but hitting url shows blank. I want this url as . Any one have any idea over this part? I have been stuck on this for around 3 days.
Here is my code:
add_action( 'wp_loaded','my_flush_rules' );
add_filter( 'rewrite_rules_array','my_insert_rewrite_rules' );
add_filter( 'query_vars','my_insert_query_vars' );
function my_flush_rules() {
$rules = get_option( 'rewrite_rules' );
if ( ! isset( $rules['(seller-login)/(.+)$'] ) ) {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
}
function my_insert_rewrite_rules( $rules ) {
$newrules = array();
$newrules['(seller-login)/(\d*)$'] = 'index.php?pagename=$matches[1]';
// var_dump($newrules);
return $newrules + $rules;
}
function my_insert_query_vars( $vars ) {
array_push($vars, 'pagename');
return $vars;
}
I want the WooCommerce way to create new rules for permalinks. I have checked WooCommerce core files and found that WooCommerce is using this filter for saving the rule in database. My current url is http://amit/wcommerce/seller-login/?page=mpProfile. I have var dumped get_query_var('pagename'); on hit page, but hitting url shows blank. I want this url as http://amit/wcommerce/seller-login/mpProfile. Any one have any idea over this part? I have been stuck on this for around 3 days.
Here is my code:
add_action( 'wp_loaded','my_flush_rules' );
add_filter( 'rewrite_rules_array','my_insert_rewrite_rules' );
add_filter( 'query_vars','my_insert_query_vars' );
function my_flush_rules() {
$rules = get_option( 'rewrite_rules' );
if ( ! isset( $rules['(seller-login)/(.+)$'] ) ) {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
}
function my_insert_rewrite_rules( $rules ) {
$newrules = array();
$newrules['(seller-login)/(\d*)$'] = 'index.php?pagename=$matches[1]';
// var_dump($newrules);
return $newrules + $rules;
}
function my_insert_query_vars( $vars ) {
array_push($vars, 'pagename');
return $vars;
}
Share
Improve this question
edited Mar 18, 2019 at 17:00
mburesh
1035 bronze badges
asked Sep 20, 2016 at 17:22
Amit ChauhanAmit Chauhan
296 bronze badges
4
- when i hit amit/wcommerce/seller-login/mpProfile i need pagename variable so that i can use this variable right now it is showing page not found – Amit Chauhan Commented Sep 20, 2016 at 17:37
- is seller-login a valid page/slug? – Ahmed Fouad Commented Sep 20, 2016 at 20:06
- Yes it is a valid slug actually it is a page – Amit Chauhan Commented Sep 21, 2016 at 5:55
- Possible duplicate, i think it's answered here wordpress.stackexchange/questions/239849/… – Ahmed Fouad Commented Sep 21, 2016 at 9:57
1 Answer
Reset to default -2things are working by using rewrite_rules_array filter 1 :- i want to know the difference between add_rewrite_url() and rewrite_rules_array filter also i want to add array of rules in rewrite_rules_array filter but currently its not working only one of the rule is working others are not thanks