你好我遇到了一个问题,希望有人可以帮助我。我在Wordpress中创建一个网站,在其中实现了某种自定义导航。
当前,我有两个分类法:toys
(分层)和producers
(标记)。基本上,这意味着该页面上的文章可以具有一个或多个生产者,并且属于玩具层次结构。
无论如何,我进行了查询,以获取所有想要的分类法。我的问题是此查询不会按层次结构顺序返回结果。
该数组由term_id
和parent
组成。
如果parent = 0表示分类法没有父级,否则它没有父级。
层次结构可以包含x个级别,它们可以随机出现在数组中(下一个级别不一定是子级别)
询问是否需要更多输入或解释。谢谢!
有人可以告诉我如何基于我拥有的数组创建如下所示的多维数组吗?
Array
(
[0] => stdClass Object
(
[term_id] => 49
[term_name] => Cars
[term_slug] => cars
[parent] => 0
)
[1] => stdClass Object
(
[term_id] => 50
[term_name] => X-series
[term_slug] => x-series
[parent] => 49
)
[2] => stdClass Object
(
[term_id] => 51
[term_name] => Yellow
[term_slug] => yellow
[parent] => 50
)
)
Array
(
[0] => stdClass Object
(
[term_id] => 49
[name] => Cars
[slug] => cars
[term_taxonomy_id] => 49
[children] => Array
(
[1] => stdClass Object
(
[term_id] => 50
[name] => X-series
[slug] => x-series
[parent] => 49
[children] => Array
(
[2] => stdClass Object
(
[term_id] => 51
[name] => Yellow
[slug] => yellow
[parent] => 50
)
)
)
)
)
)