[wp-trac] [WordPress Trac] #51552: add_query_arg() does not allow multiple query variable pairs with same key name
WordPress Trac
noreply at wordpress.org
Fri Oct 16 16:30:17 UTC 2020
#51552: add_query_arg() does not allow multiple query variable pairs with same key
name
--------------------------+-----------------------------
Reporter: RavanH | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 5.5.1
Severity: minor | Keywords:
Focuses: |
--------------------------+-----------------------------
Best shown by example for construction of a URL for a font pair from
Google Fonts following their new (css2) URL format:
{{{#!php
<?php
// desired URL in this example, notice family= appearing twice:
//
https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,400;0,700;1,400;1,700&family=Spartan:wght@200;400;500;700;800&display=swap
$fonts_url = 'https://fonts.googleapis.com/css2';
$fonts = array(
'Roboto:ital,wght at 0,400;0,700;1,400;1,700',
'Spartan:wght at 200;400;500;700;800'
);
foreach ( $fonts as $font ) {
$fonts_url = add_query_arg( 'family' , $font, $fonts_url );
}
$fonts_url = add_query_arg( 'display', 'swap', $fonts_url );
// $fonts_url will be with first key/value pair overwritten by the second
key/value pair:
//
https://fonts.googleapis.com/css2?family=Spartan%3Awght%40200%3B400%3B500%3B700%3B800&display=swap
}}}
Obviously, the way add_query_arg() is constructed using array key/value
pairs, a pair with the same key name is not possible. However, in an URL
query string, this is perfectly fine, so I'm marking this as a bug, not an
enhancement. But that might be debated ;)
--
Ticket URL: <https://core.trac.wordpress.org/ticket/51552>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list