When attempting to pass an additional variable in a WordPress URL, issues may arise when the URL contains additional information after the root domain. To resolve this, employ the following approach:
Instead of interacting with superglobals, utilize the following WordPress functions:
On the page creating the link:
In your functions.php or plugin file (front-end only):
function add_custom_query_var( $vars ) { $vars[] = "c"; return $vars; } add_filter( 'query_vars', 'add_custom_query_var' );
On the page retrieving and processing the query variable:
$my_c = get_query_var('c');
On the back end, the wp() function is not executed, so you cannot rely on the WP Query. Instead, inspect the $_GET superglobal:
$my_c = filter_input(INPUT_GET, "c", FILTER_SANITIZE_STRING);
By adhering to these recommendations, you can effectively pass additional variables in WordPress URLs, both on the front-end and back-end.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3