Re write rule not working

45 Views Asked by At

I have tried to rewrite the URl as http://example.com/book-appointment

For example

I have got a shop data by this url http://example.com/book-appointment/?shop=shop-name.

It should be work as same as url http://example.com/book-appointment/shop-name

I have tried

add_rewrite_rule('/book-appointment/([^/]*)', 'index.php?page_id=183&data=$matches[1]', 'top');

But it is not working as i write above

The full function, i have written

function custom_rewrite_basic() {
  add_rewrite_rule('^booking-now/([0-9]+)/?', 'index.php?page_id=188&data=$matches[1]', 'top');
  flush_rewrite_rules();
}
add_action('init', 'custom_rewrite_basic');
1

There are 1 best solutions below

3
On

Put below code just after your function of add_rewrite_rule :

// Add Query var
add_filter('query_vars', 'template_query_vars');
function template_query_vars( $query_vars ){
 $query_vars[] = 'page_id';
 return $query_vars;
}

Check with this. Take the reference of this link you will get more clear idea.