Advertisement
wolfcreativo

functions for Abdul Salam Ahmed

Feb 22nd, 2018
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.62 KB | None | 0 0
  1. add_action( 'init', 'listing_custom_rewrite' );
  2.  function listing_custom_rewrite(){
  3.      /*
  4.      * I ONLY USE 2 PARAMS type and search_location
  5.      *  Now you can use in your custom menus, buttons, links etc
  6.      * previous links example.com/explore/?type=rentals&location=San+diego
  7.      * New Links example.com/rentals/san-diego
  8.      */
  9.     add_rewrite_rule( '([^/]*)/region/([^/]*)/([^/]*)/?$','index.php?pagename=EXPLORE-PAGE-NAME&job-category=$matches[1]&region=$matches[2]&area=$matches[3]', 'top' );
  10.     //IMPORTANT*********Comment after first use
  11.     //flush_rewrite_rules();
  12.  }
  13.  
  14. //Create Vars to use in wordpress rewrite
  15.  add_filter( 'query_vars', 'listing_custom_query_vars');
  16.  function listing_custom_query_vars($vars) {
  17.     array_push($vars,'job-category');
  18.     array_push($vars,'region');
  19.     array_push($vars,'area');
  20.      return $vars;
  21.  }
  22. //we GET query and send to search form
  23.  add_action( 'parse_query', 'listing_get_query_vars' );
  24.  function listing_get_query_vars() {
  25.      //if you use - _ + on your url the form just recive a space
  26.     if(!empty( get_query_var( 'job-category' )) ){
  27.         $_GET['job-category'] = str_replace(array('-','_','+'),' ',get_query_var( 'sejob-categoryarch_location' ));
  28.     }
  29.     if(!empty( get_query_var( 'region' )) ){
  30.         //if you use - _ + on your url the form just recive a space
  31.         $_GET['region'] = str_replace(array('-','_','+'),' ',get_query_var( 'region' ));
  32.     }
  33.     if(!empty( get_query_var( 'area' )) ){
  34.         //if you use - _ + on your url the form just recive a space
  35.         $_GET['area'] = str_replace(array('-','_','+'),' ',get_query_var( 'area' ));
  36.     }  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement