Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.63 KB | None | 0 0
  1. function bis_detect_query_order($url) {
  2.     // Correct order
  3.     $correct_args_order = array('post_type', 'product_cat', 'pa_brand');
  4.    
  5.     $get_args = parse_url($url, PHP_URL_QUERY);
  6.    
  7.     // Get an array with $_GET params
  8.     parse_str($get_args, $get_args_array);
  9.    
  10.     // Get the names of keys
  11.     $get_args_order = array_keys($get_args_array);
  12.    
  13.     // Compare the arrays
  14.     if($get_args_order !== $correct_args_order) {
  15.         $shop_page_url = get_permalink(woocommerce_get_page_id('shop'));
  16.         wp_safe_redirect($shop_page_url, 301);
  17.         exit();
  18.     }
  19. }
  20. add_action('template_redirect', 'bis_detect_query_order', 0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement