$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>database - What does wp_term_taxonomy.parent reference?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

database - What does wp_term_taxonomy.parent reference?

matteradmin10PV0评论

My initial thought was that it referenced another taxonomy (i.e. an FK from wp_term_taxonomy.parent to wp_term_taxonomy.term_taxonomy_id). ORMs like Corcel are built under this assumption. However, I've done some digging and most information seems to indicate that it actually references wp_terms.term_id.

In the case of Corcel, I think that this coincidentally works - WordPress will set the term_id and the term_taxonomy_id to the same value. If you've messed with the data, or applied your own imports / migrations, you might not get this same behaviour.

My initial thought was that it referenced another taxonomy (i.e. an FK from wp_term_taxonomy.parent to wp_term_taxonomy.term_taxonomy_id). ORMs like Corcel are built under this assumption. However, I've done some digging and most information seems to indicate that it actually references wp_terms.term_id.

In the case of Corcel, I think that this coincidentally works - WordPress will set the term_id and the term_taxonomy_id to the same value. If you've messed with the data, or applied your own imports / migrations, you might not get this same behaviour.

Share Improve this question asked Feb 13, 2019 at 18:55 Tyler SebastianTyler Sebastian 1032 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 3

WordPress doesn't use actual FOREIGN KEY constraints in MySQL. So, technically, wp_term_taxonomy.parent is merely an integer. However, what you've found is correct: it refers to a term in wp_terms by its term_id. But, as you've also noticed, the term_id and term_taxonomy_id should always be the same.

The reason they both exists is historical. Prior to WordPress 4.2, it was possible for taxonomy terms to belong to multiple taxonomies. So you could have a single term in wp_terms that corresponded to multiple rows in wp_term_taxonomies. WordPress 4.2 changed this so that terms can only belong to a single taxonomy. You can read some of the background on this change in this Make post from 2015.

These days you should only be using term_id to refer to terms programatically, and since a term's parent is also a term, the parent value refers to another term by its term_id.

Ideally the parent property would just be in the wp_terms table, but the existing structure will likely remain in place for backwards compatibility reasons.

Post a comment

comment list (0)

  1. No comments so far