Getting/Setting Variables Rewrite URL Wordpress


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function add_my_var($public_query_vars) {
  2. $public_query_vars[] = 'myvar';
  3. return $public_query_vars;
  4. }
  5.  
  6. add_filter('query_vars', 'add_my_var');
  7.  
  8. function do_rewrite() {
  9. add_rewrite_rule('artists/(.+?)/(.+?)?$', 'index.php?pagename=artists/$matches[1]&myvar=$matches[2]','top');
  10. }
  11.  
  12. add_action('init', 'do_rewrite');

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.