• Resolved websanity

    (@websanity)


    Just checking before posting a bug report, but if you call:
    add_query_arg( ”, “http://www.test.com”);
    I’d expect to get back:
    http://www.test.com
    instead I seem to be getting back the address of the current page.
    NOTE: Easily guarded against but not obvious behaviour – should certainly be in the documentation if not seen by people as a bug.

    NOTE: I am posting a form from a WordPress shortcode on a page to an external PHP file which includes the wp core, like this:
    require_once($_SERVER[‘DOCUMENT_ROOT’].’/wp-load.php’);
    I am accessing add_query_arg() in this ‘external’ file

    So maybe that is a factor? Anybody else seen this issue?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Try it with this:

    add_query_arg( '', '', "http://www.test.com");

    Why use add_query_arg if you’re not adding any query variables?

    http://codex.ww.wp.xz.cn/Function_Reference/add_query_arg

    Thread Starter websanity

    (@websanity)

    Interesting. What was happening is that I was passing an array of query variables to it as parameter 1, and parameter 2 as the url. The query vars were auto-generated from a series of criteria which could end up with none (i.e. just leave url as is). In this case the array variable was set as ” (so NOT an empty array) which, I guess triggered it to use the three parameter option:
    add_query_arg( $param1, $param2, $old_query_or_uri );
    with param1 being ”
    and $param2 being the url
    and $old_query_or_uri not specified
    This led to the current page with my url tacked onto it in a weird fashion.
    My mistake but would be nicer if it were a little tighter on the error checking front – fraught with potential problems pushing both associative array and pairs of variables through the same function call – but I’m not a baby so I shouldn’t expect it to clean things up for me 🙂
    Thanks for your response.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Does add_query_arg() have a failure mode?’ is closed to new replies.