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.

  • Global. WP_Query. $wp_query Global WP_Query instance.

No Hooks.

Return

Array. List of post objects.

Usage

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

Code of query_posts: wp-includes/query.php VER 4.9.8

<?php
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