The query string refers to the query after the question mark in the link, formatted as Key=value, and multiple query statements separated by & symbols. The Add_query_arg () function is a handy function provided by WordPress to help you add one or more query statements to a link.
Some people will ask, add the query string directly behind the link manually appended to it? This is sometimes possible, but if the link itself has a query string, it can cause a malformed problem. And also is not conducive to PHP writing management, and the Add_query_arg () function to help you think about everything, you only need to give the query string to add a link and one or more key values and key names can be.
Usage
Add_query_arg ($key, $value, $old _query_or_uri);
Add_query_arg ($query, $old _query_or_uri);
Parameters
Add_query_arg () has two uses, the first of which requires three parameters.
$key
(Integer | String) (must) the key value of the parameter to be added, like an array, if the string is a name, and the number selects the nth argument.
Default value: None
$value
(mixed) (must) the value to be added.
Default value: None
$old _query_or_uri
(string) (optional) The link that is processed.
Default value: False, write false to $_server[' Request_uri ']
The second usage requires two parameters, using an array to pass the query string to be added to the link.
$query
(array) (must) the query to be added, the key value and the key name correspond respectively.
Default value: None
$old _query_or_uri
(string) (optional) The link that is processed.
Default value: False, write false to $_server[' Request_uri ']
return value
(string) A link to add a good query string.
Example
First usage:
echo add_query_arg (' id ', 123, ' http://www.jb51.net ');
Second usage:
echo add_query_arg (Array (' ID ' => 123), ' http://www.jb51.net ');
Two of the results are http://www.jb51.net?id=123.
Other special cases:
echo add_query_arg (Array (' ID ' => 123), ' Http://www.jb51.net?query=post ');//http://www.jb51.net?query=post& Id=123
Echo add_query_arg (array (' ID ' => 123, ' cat ' => ' themes '), ' http://www.jb51.net?query=post ');//http:/ /www.jb51.net?query=post&id=123&cat=themes
Echo add_query_arg (array (' ID ' => 123, ' cat ' => ' themes ') , ' query ' => ' page '), ' http://www.jb51.net?query=post ');//http://www.jb51.net?query=page&id=123&cat= Themes
Example
This function is located at: wp-includes/functions.php