add_query_arg() One Key with multiple values

[*]

You have to do a search and replace on $url like the following –

$url = add_query_arg( array(
    'count'    => '100',
    'property' => array(
        'abc',
        'xyz'
    )
), $base_url );

// following line will remove [*] and * can be nothing or 0-9
$api_url = preg_replace( '/\[\d*\]/', '', $url );

// Output will be like the following
// http://api-call.com/?count=100&property=abc&property=xyz 

[*]

Leave a Comment