WordPress at Your Fingertips

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.

Uses: WP_Query()

No Hooks.

Return

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

Usage

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

Notes

  • Global. WP_Query. $wp_query WordPress Query object.

Changelog

Since 1.5.0 Introduced.

Code of query_posts() WP 5.8.1

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

query

Queries

No comments
    Log In