wpseek.com
WordPress开发者和主题制作者的搜索引擎



query_posts › WordPress Function

Since1.5.0
已弃用n/a
query_posts ( $query )
参数:
  • (array|string) $query Array or string of WP_Query arguments.
    Required: Yes
返回:
  • (WP_Post[]|int[]) Array of post objects or post IDs.
定义在:
文档:

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 {@see 'pre_get_posts'} action within WP_Query. This must not be used within the WordPress Loop.


源码

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