Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between cat_id and term_id?

Tags:

php

wordpress

I'm building my own nav menu using custom taxonomies and the get_categories() method and I notice when I'm trying to pull my link for the category I can choose between cat_id and term_id. Is there a difference between the two? Which one should I be using?

Here's an example of my code using the term_id

foreach ($subcategories as $subcategory) {
    $output .= '<li><a href="'. get_category_link($subcategory->term_id) .'">' . $subcategory->name . "</a></li>\n";
}
like image 889
ItsPronounced Avatar asked Jun 07 '11 20:06

ItsPronounced


2 Answers

The two mean the same. Term_id is the actual field name in the wp_terms database table, cat_id is a frontend abbreviation, perhaps more easily understood by those working from the front end only.

like image 156
Liam Bailey Avatar answered Nov 01 '22 09:11

Liam Bailey


In short, taxonomy was added since WordPress v3.0 and is a grouping mechanism.

The best and most comprehensive answer I could find is from the Codex itself: http://codex.wordpress.org/Taxonomies#What_is_a_taxonomy.3F


To answer your question about which one you should be using, either one can work, it does depend somewhat on your application of it.

Consider Stack Overflow's tags in that when you first post a question, you can put as many tags in as you'd like; a moderator or a user with enough reputation might come along and edit it and remove tags. Why? It's usually because new tags will have no followers yet and changing or adding add a tag that has a great number of followers means there will be a greater likelihood that your question will get answered by interested parties.

like image 35
stealthyninja Avatar answered Nov 01 '22 09:11

stealthyninja