Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Talk:Function Reference/add query arg

Accuracy

  • "Retrieve a modified URL query string."

That is not what this function does. It changes the query portion of the path, unless a URL is provided.

  • "You can also retrieve the full URL with query data."

No you can't?

//  This would output 'http://blog.example.com/?p=3'
echo $_SERVER['REQUEST_URI'].'<br />';

Wrong.

//  This would output the same, but in a much more resource intensive way
echo add_query_arg ().'<br />';

Wrong.

//  This would output 'http://blog.example.com/?p=3&foo=bar'
echo add_query_arg ('foo', 'bar').'<br />';

Wrong.

//  This would output 'http://blog.example.com/?p=3&foo=bar&baz=tiny'
$arr_params = array ('foo' => 'bar',
                     'baz' => 'tiny');
echo add_query_arg ($arr_params)."<br />\";

Wrong.

  • "This function works well with wp_redirect ()"

No, it really doesn't. wp_redirect() requires an absolute URL to generate valid HTTP headers. add_query_arg() doesn't return an absolute URL unless you provide it with one.

Miqrogroove 19:34, 20 December 2009 (UTC)