is_main_query()判断是否在主查询中

目录

描述

The is_main_query() function is a conditional function that can be used to evaluate whether the current query (such as within the loop) is the "main" query (as opposed to a secondary query).

This function is most commonly used within hooks to distinguish WordPress' main query (for a page, post, or archive) from a custom/secondary query.

is_main_query() may be used with both front-end queries (theme templates, plugins, etc.), as well as admin queries. It will return true if the current query is the main query, and false if not.

is_main_query() 描述

用法

is_main_query() 用法

返回值

(boolean) 

True on success, false on failure.

is_main_query() 返回值

示例

is_main_query() 示例

历史

添加于 版本: 3.3

is_main_query() 历史

源文件

is_main_query() 函数的代码位于 wp-includes/query.php, starting line 719.

WP_Query::is_main_query() 函数的代码位于 wp-includes/query.php, starting line 3816.

is_main_query() 源文件