Let's suppose I am on this url of my site http://demo.com/?cat=1+2+3

And now someone clicks on a link generated with add_query_arg(). How can I make this link go to http://demo.com/?cat=1+2+3+4

Im trying to create a taxonomy filter and this is what I have:

foreach ( $sub_terms as $st ) {
    echo '<a href="'. esc_url( add_query_arg( $taxonomy, $st->term_id ,"http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]" ) ).'" class="subterm">'. $st->name .'</a>';

Instead of appending my term id to the url, it just replaces cat with the new value: http://demo.com/?cat=4

I hope it's clear enough


  • Are you trying to create the link or process the request?
    – s_ha_dum
    Apr 22, 2014 at 16:24
  • Trying to create the link
    – chifliiiii
    Apr 22, 2014 at 16:43

1 Answer 1


It's not "smart" enough to reason that you want to modify the value, not just set it to something.

You'll need to:

  1. retrieve the current value (get_query_var() probably)
  2. change it as needed
  3. use resulting value with add_query_arg()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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