WordPress at a glance

query_posts() WP 1.0

Sets up The Loop with query parameters.

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 'pre_get_posts' action within WP_Query.

This must not be used within the WordPress Loop.

Works based on: WP_Query()

No Hooks.


Array. List of post objects.


query_posts( $query );
$query(array/string) (required)
Array or string of WP_Query arguments.


  • Global. WP_Query. $wp_query Global WP_Query instance.


Since 1.5.0 Introduced.

Code of query posts: wp-includes/query.php WP 5.2.4

function query_posts( $query ) {
	$GLOBALS['wp_query'] = new WP_Query();
	return $GLOBALS['wp_query']->query( $query );

Related Functions

From tag: query

More from category: Queries

No comments
    Hello, !     Log In . Register