WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

As we know WordPress supports multiple tag queries (',' and '+'). The only problem with this add_query_arg() doesn't handle these methods if a query param is already exists in the URL.

From the following url www.domain.com?post_type=ptype&param=value1 add_query_arg('param', 'value2') will generate www.domain.com?post_type=ptype&param=value2 insead of www.domain.com?post_type=ptype&param=value1,value2 or value1+value2

I would only use comma separated (OR) method. Could you please help me to write a function which adds additional param value next to an exsisting one? regular expressions perhaps?

share|improve this question
up vote 0 down vote accepted
$url = parse_url( $your_url );
$query = $url['query'];

$args_arr = array();
parse_str( $query, $args_arr );

if( isset( $args_arr['param'] ) ) {
    $query_string = $args_arr['param'];
    $query_string .= ',value2';
} else {
    $query_string = 'value2';

add_query_arg( 'param', $query_string );

That's completely untested, but you get the concept. Basically, wordpress is gonna want to replace what you have set in param, so you need to get what you have in param, then add what you want to add to it. You can definitely make that into a function if you want to, depends on your usage case.

share|improve this answer
thanks it is a good idea, works great! – user9909 Mar 22 '12 at 16:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.