wp()WP 2.0.0

Set up the WordPress query.

Uses: WP::main()

No Hooks.

Return

null. Nothing.

Usage

wp( $query_vars );
$query_vars(string|array)
Default WP_Query arguments.
Default: ''

Examples

0

#1 Demo example of how this function works

Suppose we have a static page. At the very beginning of the page code, call the function as follows:

<?php wp('author=1&orderby=title&order=ASC'); ?>

Then comes the standard loop output.

As a result, the loop will display the author's posts with ID = 1, sorted by post title.

Also, the is_author() conditional tag will be triggered on this page, not is_single().

It's just demo example - not recommended to use it in you project. wp() function calls by WP itself and not considered to use somewhere else.

Notes

  • Global. WP. $wp Current WordPress environment instance.
  • Global. WP_Query. $wp_query WordPress Query object.
  • Global. WP_Query. $wp_the_query Copy of the WordPress Query object.

Changelog

Since 2.0.0 Introduced.

Code of wp() WP 5.9.3

function wp( $query_vars = '' ) {
	global $wp, $wp_query, $wp_the_query;

	$wp->main( $query_vars );

	if ( ! isset( $wp_the_query ) ) {
		$wp_the_query = $wp_query;
	}
}