tribe_get_query_var( string $url, string|array $query_arg, mixed|null $default = null )
Returns a query var parsing an input URL.
Contents
Parameters
- $url
-
(string) (Required) The URL to parse.
- $query_arg
-
(string|array) (Required) The query variable(s) to parse and return.
- $default
-
(mixed|null) (Optional) The default value to return if the URL cannot be parsed, or the query variable is not found.
Default value: null
Return
(mixed|null) The query variable value, if set, or the default value.
Source
File: src/functions/utils.php
function tribe_get_query_var( $url, $query_arg, $default = null ) {
if ( empty( $url ) ) {
return $default;
}
$query = wp_parse_url( $url, PHP_URL_QUERY );
if ( empty( $query ) ) {
return $default;
}
wp_parse_str( $query, $parsed );
if ( ! is_array( $query_arg ) ) {
return Tribe__Utils__Array::get( $parsed, $query_arg, $default );
}
$query_args = (array) ( $query_arg );
return array_intersect_key(
(array) $parsed,
array_combine( $query_args, $query_args )
);
}
Changelog
| Version | Description |
|---|---|
| 4.9.23 | Introduced. |