Welcome to FindNerd.
In a series of word-press functions, today i am going to discuss the word-press function add_query_arg. As its name implies, it is used to add arguments in a URL. First of all we discuss the parameters of this function. It has main three parameters. Please have a look.
Parameters |
Properties |
Key(array/string) |
It is a required parameter. Either pass query variable key or pass an associative array with query variable key and value. |
Value(string) |
It is optional. If you are using an associative array then the second argument should be the website URL otherwise pass the string for query variable value. |
URL(string) |
It is also optional but required if you are adding single key and value. |
From above discussion, it is clear that if you want to add multiple query strings then your first variable should be associative array otherwise pass three main parameters to achieve the result. We can take a small example to explain the concept. Please have a look.
$query_key = "id";
$query_val = 34;
$findnerd = 'http://www.findnerd.com';
$final_url = add_query_arg($query_key,$query_val,$findnerd);
//result
http://www.findnerd.com?id=34
In above code, we simply added one query string by passing three main parameters. Now look at the other example
$query_string = array('id'=>34,'rid'=>43);
$findnerd = 'http://www.findnerd.com';
$final_url = add_query_arg($query_string,$findnerd);
//result
http://www.findnerd.com?id=34&rid=43
It will return the URL by adding both the query variable in it. Thank you for being with us.
0 Comment(s)