I would like to get the query parameters passed via the URL on a WordPress site. Very easy, I've never had a problem before.
According to the address bar and dev tools my request URL is:
https://example.com/register/early/?utm_source=Testing+MemberPress+Link&utm_campaign=xxxxxxxxxx-EMAIL_CAMPAIGN&utm_medium=email&utm_term=0_-xxxxxxxxxx-%5BLIST_EMAIL_ID%5D&mc_cid=xxxxxxxx
I have tried many ways to get the query parameters. The following code:
function get_query_params() {
global $wp;
$current_url = home_url( add_query_arg( array( $_GET ), $wp->request ) );
$get_params = $_GET;
$request_params = $_REQUEST;
$query_var = get_query_var('mc_cid');
echo '<pre>URL: ' . print_r( $current_url, true ) . '</pre>';
echo '<pre>$_GET: ' . print_r( $get_params, true ) . '</pre>';
echo '<pre>$_REQUEST: ' . print_r( $request_params, true ) . '</pre>';
echo '<pre>query_var: ' . print_r( $query_var, true ) . '</pre>';
die;
}
add_action( 'parse_request', 'get_query_params' );
function add_get_val() {
global $wp;
$wp->add_query_var('mc_cid');
}
add_action('init','add_get_val', 1 );
Renders the following result
URL: https://example.com/register/early
$_GET: Array()
$_REQUEST: Array()
query_var:
Unfortunately, I have been working on this for hours, and I am unsure what else to try. I've done this many times and have never had a problem. What am I missing? Can plugins block this.
I did check the .htaccess file and nothing has been added.
parse_requestis also very very earlyparse_requestis well afterinit. It's one of the last things before the headers are set. I don't think that's extremely early. codex.wordpress.org/Plugin_API/Action_Reference$_GETis the proper way to access this, and if something is wiping it clean it's not because you're meant to use another method