函数原型
get_query_var( string $var, mixed $default = ” ): mixed
函数描述
Retrieves the value of a query variable in the WP_Query class.
是否弃用
未弃用
函数参数
-
$var
string
Required - The variable key to retrieve.
-
$default
mixed
Optional - Value to return if the query variable is not set.
Default:
''
函数返回值
mixed Contents of the query variable.
函数位置
File: wp-includes/query.php.
函数源码
function themeslug_query_vars( $qvars ) {
$qvars[] = 'custom_query_var';
return $qvars;
}
add_filter( 'query_vars', 'themeslug_query_vars' );源码链接
变更日志
| Version | Description |
|---|---|
| 3.9.0 | The $default argument was introduced. |
| 1.5.0 | Introduced. |

