如何在wordpress中将自定义帖子类型的类别和子类别作为嵌套数组?

时间:2018-04-06 15:40:24

标签: php mysql wordpress

从wordpress数据库获取数据时遇到一个小问题。我想获得一个类似的嵌套数组,如:

array(
   "id" => "1",
   "name" => "categoryName",
   "children" => array(
        [0] => array(
            "id" => "2",
            "name" => "Name1",
            "children" => ""
        )
        [1] => array(
            "id" => "3",
            "name" => "Name2",
            "children" => ""
        )
   )
)

我已经查询并得到下表:

|id   | name          | parent |
|_____|_______________|________|
|1    |categoryName   | 0      |
|_____|_______________|________|
|2    |Name1          |1       |
|_____|_______________|________|
|3    |Name2          |1       |

有什么想法吗?

0 个答案:

没有答案