get_pages_query_args
云策文档标注
概述
get_pages_query_args 是一个 WordPress 过滤器,用于修改 get_pages() 函数中传递给 WP_Query 的查询参数。它允许开发者自定义页面查询行为,例如过滤、排序或限制结果。
关键要点
- 过滤器名称:get_pages_query_args,用于在 get_pages() 中调整 WP_Query 参数。
- 参数:$query_args(传递给 WP_Query 的参数数组)和 $parsed_args(get_pages() 解析后的参数数组)。
- 支持多种查询选项,如 child_of、sort_column、hierarchical、exclude、include、meta_key、meta_value、authors、parent、exclude_tree、number、offset、post_type 和 post_status。
- 引入版本:WordPress 6.3.0。
注意事项
- include 参数不能与 child_of、parent、exclude、meta_key、meta_value 或 hierarchical 同时使用。
- meta_value 需要与 meta_key 配合使用。
- offset 参数仅在设置了 number 参数时有效。
原文内容
Filters query arguments passed to WP_Query in get_pages.
Parameters
$query_argsarray-
Array of arguments passed to WP_Query.
$parsed_argsarray-
Array of get_pages() arguments.
More Arguments from get_pages( … $args )
Array or string of arguments to retrieve pages.
child_ofintPage ID to return child and grandchild pages of. Note: The value of$hierarchicalhas no bearing on whether$child_ofreturns hierarchical results. Default 0, or no restriction.sort_orderstringHow to sort retrieved pages. Accepts'ASC','DESC'. Default'ASC'.sort_columnstringWhat columns to sort pages by, comma-separated. Accepts'post_author','post_date','post_title','post_name','post_modified','menu_order','post_modified_gmt','post_parent','ID','rand','comment*count'.
'post*'can be omitted for any values that start with it.
Default'post_title'.hierarchicalboolWhether to return pages hierarchically. If false in conjunction with$child_ofalso being false, both arguments will be disregarded.
Default true.excludeint[]Array of page IDs to exclude.includeint[]Array of page IDs to include. Cannot be used with$child_of,$parent,$exclude,$meta_key,$meta_value, or$hierarchical.meta_keystringOnly include pages with this meta key.meta_valuestringOnly include pages with this meta value. Requires$meta_key.authorsstringA comma-separated list of author IDs.parentintPage ID to return direct children of. Default -1, or no restriction.exclude_treestring|int[]Comma-separated string or array of page IDs to exclude.numberintThe number of pages to return. Default 0, or all pages.offsetintThe number of pages to skip before returning. Requires$number.
Default 0.post_typestringThe post type to query. Default'page'.post_statusstring|arrayA comma-separated list or array of post statuses to include.
Default'publish'.
Source
$query_args = apply_filters( 'get_pages_query_args', $query_args, $parsed_args );
Changelog
| Version | Description |
|---|---|
| 6.3.0 | Introduced. |