WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a built in wordpress function that let's me look up the "parent" field of the wp_term_taxonomy table if I pass the TT_ID to it?

Something like

get_value ( $wp_table_name, $id_fieldname, $id_value,
$the_field_info_to_retrieve )


get_value ( "wp_term_taxonomy", "term_taxonomy_id", "parent");
share|improve this question

My experience with this was that it is an issue area of the taxonomy system in core. In several cases the core code does fetch info based on a tt_id or an array of them, but in each of these cases it is painfully done with a custom SQL query inside that particular function rather than an API function.

To solve my own problem I wrote a simple helper function that should probably be in core. It doesn't fetch a specific field but instead the entire term_taxonomy row (including ->parent). Ultimately this is no slower than getting a single field and it is a very fast query due to checking for a specific ID.

 * Fetch the term_taxonomy data for a tt_id from the term_taxonomy table
 * Should be in core but isn't. May need review after updates
 * Returns full full row of data but nothing from actual terms table.
 * @global object $wpdb
 * @param integer $tt_id term_taxonomy_id who's row you want to fetch.
 * @return object Database row object for tt_id (term_id, name, slug, taxonomy, description, parent, count)
function gv_get_term_taxonomy_details($tt_id) {
    global $wpdb;
    $tt_details_results = $wpdb->get_results("SELECT * FROM $wpdb->term_taxonomy WHERE term_taxonomy_id = ($tt_id)");
    $tt_details = $tt_details_results[0];

    return $tt_details;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.