wordpress - 父母的Wordpress wp_get_post_terms订单未正确订购子孙
问题描述
我认为我的问题的开始是父子孙没有按层次顺序排列的 ID,父类别是在子类别之后添加的,所以我无法正确排序它们。
我想获取自定义帖子类型的自定义分类列表,为此我使用该函数wp_get_post_terms
列出分类。但我无法按顺序获得它们parent
> children
>grandchildren
从 wordpress 文档中这应该可以工作:
wp_get_post_terms($edit_post->ID, 'listings_category', array("fields" => "ids", "orderby" => "parent"));
但是孙子类别总是列在子类别之前。
这是类别列表:
Services
-- Design
-- Artistic
但在数据库中,他们的 id 不是分层的
Services => id(454)
Design => id(43)
Artistic => id(44)
而且我不能让它们按顺序显示Services
>>Design
Artistic
他们总是以不同的顺序结束。
这是一个数组输出
array(3) {
[0]=>
object(WP_Term)#7074 (10) {
["term_id"]=>
int(494)
["name"]=>
string(8) "Services"
["slug"]=>
string(8) "services"
["term_group"]=>
int(0)
["term_taxonomy_id"]=>
int(494)
["taxonomy"]=>
string(17) "listings_category"
["description"]=>
string(0) ""
["parent"]=>
int(0)
["count"]=>
int(1)
["filter"]=>
string(3) "raw"
}
[1]=>
object(WP_Term)#7073 (10) {
["term_id"]=>
int(44)
["name"]=>
string(20) "Artistic"
["slug"]=>
string(18) "artistic"
["term_group"]=>
int(0)
["term_taxonomy_id"]=>
int(44)
["taxonomy"]=>
string(17) "listings_category"
["description"]=>
string(0) ""
["parent"]=>
int(43)
["count"]=>
int(1)
["filter"]=>
string(3) "raw"
}
[2]=>
object(WP_Term)#7075 (10) {
["term_id"]=>
int(43)
["name"]=>
string(23) "Design"
["slug"]=>
string(23) "design"
["term_group"]=>
int(0)
["term_taxonomy_id"]=>
int(43)
["taxonomy"]=>
string(17) "listings_category"
["description"]=>
string(0) ""
["parent"]=>
int(494)
["count"]=>
int(1)
["filter"]=>
string(3) "raw"
}
}
解决方案
推荐阅读
- php - Laravel 错误:您的系统中缺少请求的 PHP 扩展 sqlite3
- spring-boot - springboot程序启动时,filter会多次过滤同一路径。这是什么原因?
- javascript - 自定义按钮上的执行触发器问题 > Apexchat
- python - matplotlib 以自定义日期格式和间隔显示 x 轴
- php - 在用户个人资料部分创建自定义字段以上传用户的简历
- php - 如何在 Find() 的 where() 中添加 orderBy()?
- azure - 内存中的 Service Fabric 有状态服务与外部存储
- mysql - 确定客户记录的相关子查询
- actions-on-google - 操作已发布,但仍不显示在其他帐户中
- aspnetboilerplate - 将 JSON 序列化从 camelCase 更改为 PascalCase [重复 - 没有解决方案?]