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.


WP_Post[]|Int[]. Array of post objects or post IDs.


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


  • Global. WP_Query. $wp_query WordPress Query object.


Since 1.5.0 Introduced.

Code of query_posts() WP 5.7.1

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

From tag: query

More from category: Queries

No comments
    Log In