admin管理员组

文章数量:1287650

there. I've tried tons of solutions I've found in this forum before asking this. It's kind of hard for me to understand the php sintaxe. I have no idea how to do this and i've been stuck for days trying hundreds of codes. Can someone help me?

I have the following categories:

- Animal
-- Dog
--- frenchie-1
--- frenchie-2
--- frenchie-3

Animal > Dog > frenchie-3

I need to get the slug from "frenchie-3", that is the last one in this situation. Maybe in the future will be a frenchie-4 and I would need to retrieve this "new last" category of that child category. I will always need the last one.

Thanks a lot for your attention.

there. I've tried tons of solutions I've found in this forum before asking this. It's kind of hard for me to understand the php sintaxe. I have no idea how to do this and i've been stuck for days trying hundreds of codes. Can someone help me?

I have the following categories:

- Animal
-- Dog
--- frenchie-1
--- frenchie-2
--- frenchie-3

Animal > Dog > frenchie-3

I need to get the slug from "frenchie-3", that is the last one in this situation. Maybe in the future will be a frenchie-4 and I would need to retrieve this "new last" category of that child category. I will always need the last one.

Thanks a lot for your attention.

Share Improve this question asked Nov 6, 2021 at 4:33 JayJay 111 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 1

I've finally figured out the result I wanted with get_categories:

get_categories( array(
    'orderby' => 'name',   // get the name of category
    'order'   => 'DESC',   // descending order
    'parent'  => 14,       // category_id
    'number' => 1          // only one category (the last one, because DESC)
));

本文标签: phpHow to get the last category name of a child category