get_terms_args
云策文档标注
概述
get_terms_args 是一个 WordPress 过滤器,用于修改 get_terms() 函数的查询参数。它允许开发者在获取分类法术语时自定义查询条件,如排序方式。
关键要点
- 过滤器名称:get_terms_args
- 参数:$args(数组,包含 get_terms() 的参数)和 $taxonomies(字符串数组,分类法名称)
- 用途:过滤术语查询参数,常用于调整排序、筛选等查询行为
- 相关函数:get_terms() 和 WP_Term_Query::get_terms()
- 引入版本:WordPress 3.1.0
代码示例
/**
* Order categories
*
*/
function wp_custom_sort_get_terms_args( $args, $taxonomies )
{
$args['orderby'] = 'description';
$args['order'] = 'ASC';
return $args;
}
add_filter( 'get_terms_args', 'wp_custom_sort_get_terms_args', 10, 2 );注意事项
- 还有一个 get_terms_orderby 过滤器专门用于调整术语排序查询,可根据需要选择使用。
原文内容
Filters the terms query arguments.
Parameters
$argsarray-
An array of get_terms() arguments.
More Arguments from get_terms( … $args )
Array or string of arguments. See WP_Term_Query::__construct() for information on accepted arguments.
$taxonomiesstring[]-
An array of taxonomy names.
Source
$args = apply_filters( 'get_terms_args', $args, $taxonomies );
Changelog
| Version | Description |
|---|---|
| 3.1.0 | Introduced. |
Skip to note 2 content
Jose Lazo
To reorder categories list in
functions.php/** * Order categories * */ function wp_custom_sort_get_terms_args( $args, $taxonomies ) { $args['orderby'] = 'description'; $args['order'] = 'ASC'; return $args; } add_filter( 'get_terms_args', 'wp_custom_sort_get_terms_args', 10, 2 );