Issue: I have the term_taxonomy_id, I do not have the taxonomy name, I want to retrieve the term object without doing a direct database query.
Thoughts: Well the API docs for get_term_by say that taxonomy is required and the wp_term_taxonomy table schema makes it pretty simple to get the taxonomy if I have the term_taxonomy_id so this should be pretty simple — however I don’t seem to see any API calls that can achieve this.
I could just call the database using something like:
select taxonomy from wp_term_taxonomy where term_taxonomy_id={ID}
But would prefer not to do a direct query to the database. Is there an API call that can achieve this? or a better way to get the term object from the term_taxonomy_id?
Thanks
I was pretty sure of this, but the answer is—at least for now—a definitive no. There isn’t an API call for it.
To double-check, I asked core developer Andrew Nacin about this on Twitter. His response:
term_taxonomy_id is, for the moment, essentially private. You should likely never have it to use it.
It might be worth posting a second question about whatever you’re doing or at least expanding on the particular situation that leads to this scenario, since your current problem is rather rare—and maybe unnecessary—in the first place. Again from Nacin:
I honestly don’t know when you’d ever have term_taxonomy_id and not also already be in a position to know term_id and taxonomy.
Addendum: It should also be noted that the taxonomy schema and meta relationships are slated to undergo some changes, so this may be a particularly dangerous time to try something outside the API.