函数文档

wp()

💡 云策文档标注

概述

wp() 函数用于设置 WordPress 查询,通过调用 WP::main() 来初始化查询变量和环境。

关键要点

  • 参数 $query_vars 为字符串或数组,用于指定 WP_Query 的默认参数。
  • 函数内部调用 $wp->main($query_vars) 来设置查询,并处理全局变量 $wp_the_query。
  • wp() 函数自 WordPress 2.0.0 版本引入,是核心查询设置函数。

相关用途

  • WP::main():设置 WordPress 环境所需的所有变量。
  • wp_edit_posts_query():在编辑文章页面运行查询以获取文章列表。
  • wp_edit_attachments_query():执行附件查询,可传入 WP_Query 参数覆盖默认设置。

📄 原文内容

Sets up the WordPress query.

Parameters

$query_varsstring|arrayrequired
Default WP_Query arguments.

Source

function wp( $query_vars = '' ) {
	global $wp, $wp_query, $wp_the_query;

	$wp->main( $query_vars );

	if ( ! isset( $wp_the_query ) ) {
		$wp_the_query = $wp_query;
	}
}

Changelog

Version Description
2.0.0 Introduced.