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;
}
things 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