Filter hook 'query_vars'

in WP Core File wp-includes/class-wp.php at line 311

View Source

query_vars

Filter Hook
Description
Filters the query variables allowed before processing. Allows (publicly allowed) query vars to be added, removed, or changed prior to executing the query. Needed to allow custom rewrite rules using your own arguments to work, or any other custom query variables you want to be publicly available.

Hook Information

File Location wp-includes/class-wp.php View on GitHub
Hook Type Filter
Line Number 311

Hook Parameters

Type Name Description
string[] $public_query_vars The array of allowed query variable names.

Usage Examples

Basic Usage
<?php
// Hook into query_vars
add_filter('query_vars', 'my_custom_filter', 10, 1);

function my_custom_filter($public_query_vars) {
    // Your custom filtering logic here
    return $public_query_vars;
}

Source Code Context

wp-includes/class-wp.php:311 - How this hook is used in WordPress core
<?php
 306  		 *
 307  		 * @since 1.5.0
 308  		 *
 309  		 * @param string[] $public_query_vars The array of allowed query variable names.
 310  		 */
 311  		$this->public_query_vars = apply_filters( 'query_vars', $this->public_query_vars );
 312  
 313  		foreach ( get_post_types( array(), 'objects' ) as $post_type => $t ) {
 314  			if ( is_post_type_viewable( $t ) && $t->query_var ) {
 315  				$post_type_query_vars[ $t->query_var ] = $post_type;
 316  			}

PHP Documentation

<?php
/**
		 * Filters the query variables allowed before processing.
		 *
		 * Allows (publicly allowed) query vars to be added, removed, or changed prior
		 * to executing the query. Needed to allow custom rewrite rules using your own arguments
		 * to work, or any other custom query variables you want to be publicly available.
		 *
		 * @since 1.5.0
		 *
		 * @param string[] $public_query_vars The array of allowed query variable names.
		 */
Quick Info
  • Hook Type: Filter
  • Parameters: 1
  • File: wp-includes/class-wp.php
Related Hooks

Related hooks will be displayed here in future updates.