本文最后更新于 2022-10-17,已超过 365 天未更新,内容可能已失效。
使用查询参数设置循环。
Sets up The Loop with query parameters.
说明(Description)
注意:此函数将完全覆盖主查询,不打算由插件或主题使用。它过于简单的修改主查询的方法可能有问题,应该尽可能避免。在大多数情况下,有更好的、性能更好的选项用于修改主查询,例如通过WP_查询中的“pre_get_posts”操作。
这不能在WordPress循环中使用。
参数(Parameters)
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| $query | (array | string) | 必需 | WP_查询参数的数组或字符串。 |
返回(Return)
(WP_Post[]|int[])Post对象或Post id的数组。
源码(Source)
/**
* Set up The Loop with query parameters.
*
* This will override the current WordPress Loop and shouldn't be used more than
* once. This must not be used within the WordPress Loop.
*
* @since 1.5.0
*
* @global WP_Query $wp_query
*
* @param string $query
* @return array List of posts
*/
function query_posts($query) {
$GLOBALS['wp_query'] = new WP_Query();
return $GLOBALS['wp_query']->query($query);
}
| 更新版本 | 源码位置 | 使用 | 被使用 |
|---|---|---|---|
| 1.5.0 | wp-includes/query.php:96 | 0 | 1 function |
除非注明,子佩工作室 文章均为原创,转载请以链接形式标明本文地址。



登录后即可发表评论
全部评论 (0)