Sets up The Loop with query parameters.


(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.


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

Defined (1)

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

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