Opened 3 years ago
Last modified 15 months ago
#53319 new enhancement
Add support for a "reverse" argument in get_term_parents_list() function
Reported by: | bedas | Owned by: | |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | normal | Version: | |
Component: | Taxonomy | Keywords: | has-patch needs-unit-tests |
Focuses: | Cc: |
Description
Please bare with me, I probably do everything wrong since it is my first Trac Ticket involving code.
---
Recently I used get_term_parents_list()
to create a list of hierarchical terms.
I noticed that by default the function outputs the terms like so:
Parent Category/Child Category/Grandchild Category
I could not find any argument or way to invert that order, with the goal to display the terms like so:
Grandchild Category/Child Category/Parent Category
This is useful for example if we have Geographic zones and the utmost parent is a Country, the utmost child an area. In that case we may want to display Area/Region/Country which looks like an address structure rather than the opposed which is the default
I don't think it should be too hard adding this new argument to the function.
I have uploaded a file with the modified function and updated code comment to the ticket.
I also tested my changes on a existing install and can confirm this introduced no unexpected issues.
It would be awesome to see if we can add this tiny change in future release.
Attachments (3)
Change History (18)
#2
@
3 years ago
@joyously afaik, the get_ancestors function returns An array of IDs of ancestors from lowest to highest in the hierarchy.
Thus, Because the get_ancestors doesn’t provide the current/start term and that term is added within get_term_parents_list only and it’s added at the begin of the terms list, if you invert the array in get_ancestors you would get Child Category/Parent Category/Grandchild Category as a result of get_term_parents_list
Maybe I’m wrong but this is what I saw in the code
#3
follow-up:
↓ 4
@
3 years ago
Do we really need to down load and upload the proposed code change for each and every single edit?
---
That said, changed terminology from inverse to reverse and added check for boolean thanks @joyously for the heads up.
Attached new file to ticket.
#4
in reply to:
↑ 3
;
follow-up:
↓ 7
@
3 years ago
Replying to bedas:
Do we really need to down load and upload the proposed code change for each and every single edit?
You shouldn't need to download the code change, only upload a new patch or diff file. As described here: https://make.wordpress.org/core/handbook/tutorials/working-with-patches/
This ticket was mentioned in Slack in #core by jnylen. View the logs.
3 years ago
#6
follow-up:
↓ 9
@
3 years ago
- Component changed from General to Taxonomy
- Keywords needs-refresh added
- Version trunk deleted
@jnylen0 is 53319.diff working for you?
@type bool $reverse Wether to reverse the hierarchical order of the Terms on output. Default true.
Also, please change the Whether
spell.
#7
in reply to:
↑ 4
@
3 years ago
Replying to jnylen0:
Replying to bedas:
Do we really need to down load and upload the proposed code change for each and every single edit?
You shouldn't need to download the code change, only upload a new patch or diff file. As described here: https://make.wordpress.org/core/handbook/tutorials/working-with-patches/
You can also submit a pull request on GitHub. Just make sure to include the ticket URL in the PR description, and it will be automatically linked to the ticket.
#9
in reply to:
↑ 6
@
3 years ago
- Keywords needs-unit-tests added
Replying to mukesh27:
@jnylen0 is 53319.diff working for you?
I've not tested this but the author reports that it is working as intended on multiple sites. A unit test or two would be good to confirm correct operation now and in the future.
Also, not sure if this needs an @since
annotation for the new parameter?
#10
@
3 years ago
Also, I think calling this argument parents_first
(default true
) or children_first
(default false
) would be more descriptive. reverse
isn't immediately clear about what it is reversing until you look in the code and see that it's related to the use of the array_reverse
function.
This ticket was mentioned in Slack in #core by hellofromtonya. View the logs.
3 years ago
#12
@
3 years ago
- Milestone changed from 5.9 to Future Release
Today is 5.9 Feature Freeze. As there's more to do, punting this one to the next cycle. But as the next cycle isn't yet available in the milestones, it's set to Future Release
. Sorry about that. Once available, please feel free to move into 6.0.
This ticket was mentioned in PR #1859 on WordPress/wordpress-develop by TukuToi.
3 years ago
#13
- Keywords needs-refresh removed
Order hierarchy for term names. If true, the terms returned are ordered from parent to child. If false, the terms returned are ordered from child to parent. Default is true. Accepts bool false|true.
Trac ticket: [](https://core.trac.wordpress.org/ticket/53319)
Updated method get_term_parents_list that is registered in category-template.php currently on line 1377