Title: WP_Query::fill_query_vars
Published: April 25, 2014
Last modified: April 28, 2025

---

# WP_Query::fill_query_vars( array $query_vars ): array

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wp_query/fill_query_vars/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_query/fill_query_vars/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_query/fill_query_vars/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_query/fill_query_vars/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_query/fill_query_vars/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_query/fill_query_vars/?output_format=md#wp--skip-link--target)

Fills in the query variables, which do not exist within the parameter.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_query/fill_query_vars/?output_format=md#parameters)󠁿

 `$query_vars`arrayrequired

Defined query variables.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_query/fill_query_vars/?output_format=md#return)󠁿

 array Complete query variables with undefined ones filled in empty.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_query/fill_query_vars/?output_format=md#source)󠁿

    ```php
    public function fill_query_vars( $query_vars ) {
    	$keys = array(
    		'error',
    		'm',
    		'p',
    		'post_parent',
    		'subpost',
    		'subpost_id',
    		'attachment',
    		'attachment_id',
    		'name',
    		'pagename',
    		'page_id',
    		'second',
    		'minute',
    		'hour',
    		'day',
    		'monthnum',
    		'year',
    		'w',
    		'category_name',
    		'tag',
    		'cat',
    		'tag_id',
    		'author',
    		'author_name',
    		'feed',
    		'tb',
    		'paged',
    		'meta_key',
    		'meta_value',
    		'preview',
    		's',
    		'sentence',
    		'title',
    		'fields',
    		'menu_order',
    		'embed',
    	);

    	foreach ( $keys as $key ) {
    		if ( ! isset( $query_vars[ $key ] ) ) {
    			$query_vars[ $key ] = '';
    		}
    	}

    	$array_keys = array(
    		'category__in',
    		'category__not_in',
    		'category__and',
    		'post__in',
    		'post__not_in',
    		'post_name__in',
    		'tag__in',
    		'tag__not_in',
    		'tag__and',
    		'tag_slug__in',
    		'tag_slug__and',
    		'post_parent__in',
    		'post_parent__not_in',
    		'author__in',
    		'author__not_in',
    		'search_columns',
    	);

    	foreach ( $array_keys as $key ) {
    		if ( ! isset( $query_vars[ $key ] ) ) {
    			$query_vars[ $key ] = array();
    		}
    	}

    	return $query_vars;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-query.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/class-wp-query.php#L572)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/class-wp-query.php#L572-L644)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_query/fill_query_vars/?output_format=md#related)󠁿

| Used by | Description | 
| [WP_Query::get_posts()](https://developer.wordpress.org/reference/classes/wp_query/get_posts/)`wp-includes/class-wp-query.php` |

Retrieves an array of posts based on query variables.

  | 
| [WP_Query::parse_query()](https://developer.wordpress.org/reference/classes/wp_query/parse_query/)`wp-includes/class-wp-query.php` |

Parses a query string and sets query type booleans.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_query/fill_query_vars/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.5.0](https://developer.wordpress.org/reference/since/4.5.0/) | Removed the `comments_popup` public query variable. | 
| [2.1.0](https://developer.wordpress.org/reference/since/2.1.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_query%2Ffill_query_vars%2F)
before being able to contribute a note or feedback.