add_query_arg [ WordPress Function ]
| Parameters: |
|
| Returns: |
|
| Defined at: |
|
Retrieve a modified URL query string.
You can rebuild the URL and append a new query variable to the URL query by using this function. You can also retrieve the full URL with query data.
Adding a single key & value or an associative array. Setting a key value to an empty string removes the key. Omitting oldquery_or_uri uses the $_SERVER value. Additional values provided are expected to be encoded appropriately with urlencode() or rawurlencode().
Source
<?php
function add_query_arg() {
$ret = '';
if ( is_array( func_get_arg(0) ) ) {
if ( @func_num_args() < 2 || false === @func_get_arg( 1 ) )
$uri = $_SERVER['REQUEST_URI'];
else
$uri = @func_get_arg( 1 );
} else {
if ( @func_num_args() < 3 || false === @func_get_arg( 2 ) )
$uri = $_SERVER['REQUEST_URI'];
else
$uri = @func_get_arg( 2 );
}
if ( $frag = strstr( $uri, '#' ) )
$uri = substr( $uri, 0, -strlen( $frag ) );
else
$frag = '';
if ( preg_match( '|^https?://|i', $uri, $matches ) ) {
$protocol = $matches[0];
$uri = substr( $uri, strlen( $protocol ) );
} else {
$protocol = '';
}
if ( strpos( $uri, '?' ) !== false ) {
$parts = explode( '?', $uri, 2 );
if ( 1 == count( $parts ) ) {
$base = '?';
$query = $parts[0];
} else {
$base = $parts[0] . '?';
$query = $parts[1];
}
} elseif ( !empty( $protocol ) || strpos( $uri, '=' ) === false ) {
$base = $uri . '?';
$query = '';
} else {
$base = '';
$query = $uri;
}
wp_parse_str( $query, $qs );
$qs = urlencode_deep( $qs ); // this re-URL-encodes things that were already in the query string
if ( is_array( func_get_arg( 0 ) ) ) {
$kayvees = func_get_arg( 0 );
$qs = array_merge( $qs, $kayvees );
} else {
$qs[func_get_arg( 0 )] = func_get_arg( 1 );
}
foreach ( (array) $qs as $k => $v ) {
if ( $v === false )
unset( $qs[$k] );
}
$ret = build_query( $qs );
$ret = trim( $ret, '?' );
$ret = preg_replace( '#=(&|$)#', '$1', $ret );
$ret = $protocol . $base . $ret . $frag;
$ret = rtrim( $ret, '?' );
return $ret;
}
?>
Examples [ wp-snippets.com ]
Top Google zoekresultaten
- Function Reference/add query arg « WordPress Codex
Description. Retrieve a modified URL (with) query string. You can rebuild the URL and append a new query variable to the URL query by using this function.
codex.wordpress.org - Adding GET params to a URL in WordPress with add_query_arg ...
Feb 13, 2009 ... add_query_arg(); ... $some_url = add_query_arg( $params, $some_url ); ... in the URL, you can just hand all that hassle to add_query_arg.
www.simonwheatley.co.uk - plugins - add_query_arg not working - WordPress
Nov 30, 2010 ... I added a filter to append a parameter onto the URL when navigating in categories. This is used to sort posts by their votes when browsing a ...
wordpress.stackexchange.com - help with php echo add_query_arg - Web Hosting Talk
<?php echo add_query_arg( 'tab' => 'allmedia', 'genre' ... If so, you'll need to construct the array separately from the add_query_arg function.
www.webhostingtalk.com
Gebruikersdiscussies [ wordpress.org ]
- nicolaelvin on "How to pass variables in my url whilst using 'pretty' permalinks"
- nicolaelvin on "How to pass variables in my url whilst using 'pretty' permalinks"
- nicolaelvin on "How to pass variables in my url whilst using 'pretty' permalinks"
- ClaytonJames on "How to pass variables in my url whilst using 'pretty' permalinks"
- nicolaelvin on "How to pass variables in my url whilst using 'pretty' permalinks"
- ClaytonJames on "How to pass variables in my url whilst using 'pretty' permalinks"
- nicolaelvin on "How to pass variables in my url whilst using 'pretty' permalinks"
- nicolaelvin on "How to pass variables in my url whilst using 'pretty' permalinks"
- IshaanRawat on "How to pass variables in my url whilst using 'pretty' permalinks"
- nicolaelvin on "How to pass variables in my url whilst using 'pretty' permalinks"