6

I'm trying to use wordpress' add_query_arg function to add multiple queries to my url.

I can successfully add one query as follows:

esc_url(add_query_arg( 'booking-id', $the_query->post->ID, site_url( '/booking-form/' ) ))

However, I want my URL to read something like: www.yoursite.com/booking-form/?booking-id=xxx&user-id=xxx

How can I add a second query in to the existing function?

3 Answers 3

14

Take a look at the official help on the function: https://developer.wordpress.org/reference/functions/add_query_arg/

// Parameters as array of key => value pairs
add_query_arg( array('key1' => 'value1', ...), $old_query_or_uri );

So for your example....

add_query_arg( array('booking-id' => $the_query->post->ID, 
  'user-id' => $userID),
  site_url( '/booking-form/' ) 
);

Where $userID is your user ID value (however you wish to get this)

Sign up to request clarification or add additional context in comments.

Comments

0

I referred add_query_arg code reference and written this, I hope this will be helpful, please try and let me know.

$old_query_or_uri = '/booking-form/';
add_query_arg( array('booking-id' = 'xxx', 'user-id' = 'xxx' ), $old_query_or_uri );

Comments

0
http://yoursite.com/?view=grid

<?php echo home_url('?view=list'); ?>

similer to 

<?php echo add_query_arg( 'view', 'list', home_url() ); ?>

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.