Opened 12 years ago
Closed 12 years ago
#30941 closed feature request (invalid)
Get taxonomy terms by post ID and order/orderby
| Reported by: | miyarakira | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Taxonomy | Version: | 4.1 |
| Severity: | minor | Keywords: | close |
| Cc: | Focuses: |
Description
I have a situation where I need to get taxonomy terms, optionally by associated post ID, and sorted by order/orderby.
The issue:
- get_terms accepts order/orderby (and other parameters) but not post ID, as far as I could see
- get_the_terms accepts post ID but not order/orderby.
So when I need the terms by post ID, I can't have them sorted. Here's another person who wanted to sort by term slug, and the recommendation was to sort them manually after get_the_terms.
I read the Codex on both functions and looked into their respective code: get_terms in taxonomy.php, and get_the_terms in category-template.php. Is it possible to achieve what I want currently? If not, it would be helpful to have either:
1) order/orderby in get_the_terms
2) post_id in get_terms
Change History (5)
#2
@
12 years ago
Hi miyarakira - Why not just use wp_get_object_terms() directly? (The problem with adding support in get_terms() is that the we'll have to have separate caches for each value of the $args passed to wp_get_object_terms()).
#3
@
12 years ago
Thank you for the suggestion, that solved my issue.
- Get taxonomy terms without post ID:
get_terms - Get taxonomy terms with post ID and order/orderby:
wp_get_object_terms - Get taxonomy terms with post ID without order/orderby:
get_the_termsto take advantage of the cache
Well, it looks like I should have posted this in the support forum instead of raising a ticket - at least I learned something new. During the process I set up a development version of WordPress via SVN, so I'm able to submit patches to core now - cool! :)
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
It seems #1 would be easier to achieve. get_the_terms could accept an optional third parameter, to be passed as argument to wp_get_object_terms (which does take order/orderby).