Guest User

Untitled

a guest
Feb 22nd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. add_action( 'init', 'listing_search_url' );
  2. function listing_search_url()
  3. {
  4. add_rewrite_tag('%type%', '([^&]+)');
  5. add_rewrite_tag('%search_location%', '([^&]+)');
  6. add_rewrite_rule(
  7. '^custom(/([^/]+))?/(/([^/]+))?/?',
  8. 'index.php?page_id=23&type=$matches[2]&search_location=$matches[4]',
  9. 'top'
  10. );
  11. flush_rewrite_rules();
  12. }
  13.  
  14. function wpd_foo_get_param() {
  15. if( false !== get_query_var( 'search_location' ) ){
  16. $_GET['search_location'] = get_query_var( 'search_location' );
  17. }
  18. }
  19. add_action( 'parse_query', 'wpd_foo_get_param' );
  20.  
  21. add_action( 'parse_query', 'listing_get_query_vars' );
  22. function listing_get_query_vars() {
  23. //if you use - _ + on your url the form just recive a space
  24. if(!empty( get_query_var( 'search_location' )) ){
  25. $_GET['search_location'] = str_replace(array('-','_','+'),' ',get_query_var( 'search_location' ));
  26. }
  27. }
  28.  
  29. function wpd_foo_get_param() {
  30. if( false !== get_query_var( 'search_location' ) ){
  31. $_GET['search_location'] = get_query_var( 'search_location' );
  32. }
  33. }
  34. add_action( 'parse_query', 'wpd_foo_get_param' );
Add Comment
Please, Sign In to add comment