wp_reset_vars() WordPress Function

The wp_reset_vars() function resets the global variables that are used to store the results of a WordPress query. This function is useful if you want to run multiple queries on a single page.

wp_reset_vars( array $vars ) #

Resets global variables based on $_GET and $_POST.


Description

This function resets global variables based on the names passed in the $vars array to the value of $_POST[$var] or $_GET[$var] or ” if neither is defined.


Top ↑

Parameters

$vars

(array)(Required)An array of globals to reset.


Top ↑

Source

File: wp-admin/includes/misc.php

function wp_reset_vars( $vars ) {
	foreach ( $vars as $var ) {
		if ( empty( $_POST[ $var ] ) ) {
			if ( empty( $_GET[ $var ] ) ) {
				$GLOBALS[ $var ] = '';
			} else {
				$GLOBALS[ $var ] = $_GET[ $var ];
			}
		} else {
			$GLOBALS[ $var ] = $_POST[ $var ];
		}
	}
}


Top ↑

Changelog

Changelog
VersionDescription
2.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.