query_posts

Sets up The Loop with query parameters.

Description

(array) query_posts( (array|string) $query ); 

Note: This function will completely override the main query and isn't intended for use by plugins or themes. Its overly-simplistic approach to modifying the main query can be problematic and should be avoided wherever possible. In most cases, there are better, more performant options for modifying the main query such as via the action within WP_Query.

This must not be used within the WordPress Loop.

Returns (array)

List of post objects.

Parameters (1)

0. $query (array|string)
Array or string of WP_Query arguments.

Usage

  1. if ( !function_exists( 'query_posts' ) ) { 
  2. require_once ABSPATH . WPINC . '/query.php'; 
  3.  
  4. // Array or string of WP_Query arguments. 
  5. $query = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = query_posts($query); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/query.php  
  1. function query_posts($query) { 
  2. $GLOBALS[wp_query] = new WP_Query(); 
  3. return $GLOBALS[wp_query]->query($query);