title: Redirect URL based on URL query string
body: <p>I want to redirect a URL based on URL query string for a custom post type. </p>
  
  <p>Example URL: <a href="http://example.com/custom_post_type/post-name?et_fb=1" rel="nofollow">http://example.com/custom_post_type/post-name?et_fb=1</a></p>
  
  <p>I want to check if the URL has the query string <strong>?et_fb=1</strong> and if so do not redirect else redirect to admin page. I tried with the following function but it does not take me to the admin URL</p>
  
  <pre><code>function redirect_cpt_to_admin() {
      $url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
      $redirect = strpos($url,'?et_fb') == false;
  
      global $wp_query;
      if ( is_singular('my_cpt') &amp;&amp; $redirect ){
          $admin_url   = admin_url();
          wp_redirect( esc_url_raw( $admin_url ), 301 );
          exit(); 
  }
  }
  add_action ( 'template_redirect', 'redirect_cpt_to_admin', 20);
  </code></pre>