I am busy developing a WordPress application and I need to be able to pass url parameters using WordPress functions. I use add_query_arg()
function to add a url parameter. However, when I try to get the passed value in the other page using get_query_var()
nothing gets returned. When I used $_GET['var_name']
the values gets returned.
What is the possible cause of this situation? I can successfully add arguments to the url but I am not able to access them.
If you check out the Codex, you'll see you actually need to do some fiddling to get WP to start reading your query string.
Codex (under Custom Query Vars)
Excerpt:
I managed to get the
get_query_var()
function to work. To use the two functions successfully, you need to add the query vars to wordpress's query vars array. Here is a code sample.Now you can use
get_query_var()
andadd_query_arg()
as follows:Add the query var and value
Get the query var value
More information and code samples can be found at the Codex: get_query_var and add_query_arg
To troubleshoot, what variables are being used in the request use following code