wordpress add_query_arg how to add multiple queries to URL

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:

Read More
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?

Related posts

3 comments

  1. 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)

  2. 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 );
    
  3. http://yoursite.com/?view=grid
    
    <?php echo home_url('?view=list'); ?>
    
    similer to 
    
    <?php echo add_query_arg( 'view', 'list', home_url() ); ?>
    

Comments are closed.