0

It seems that Wordpress has default categories with default (and unchangeable) IDs. For example, the uncategorized category seems to always have an id of 1. Is this always the case? Is there any official documentation for this (and other default category IDs)?

Question (big picture)

How to view a list of these default categories and ids?

Question (contextual)

I'm using get_terms to view a list of categories for post filtering. unpublished is being returned as a category, though for obvious reasons it's not desirable (on a site's frontend) to filter posts by those not yet published, so I need to exclude it. I've figured out that at least on my particular Wordpress install the unpublished category ID is 50. Is this always the case?

Many thanks.

1

There is only one default term in Wordpress, that is the term uncategorized from the taxonomy category. This term is created when Wordpress is first installed. This term's ID will always be 1 if it is not altered in any other way by some custom code from a custom theme or plugin.

Term ids, like post ids, are very reliable and does not change within a specific installation unless they are altered by their relevant update_* functions like wp_update_term() which is used to modify term field values of an already created term. Here the term id will change if the term_id field is explicitely set to anything else outside the original term id. Also, if a term is deleted, and it is recreeated, the term id will also differ from the previous one.

Term ids, like post ids, will differ between different installs ( except for the term uncategorized, and the "Hello World" post ) as ids are assigned numerically ascending order in the order the post or term is created. In one install, if a term with slug term is created as the seventh term, it will have an id of 7, on another install, if the same term was created tenth, it will have an id of 10.

To get a term id is easy, go to the categories page ( or tag or custom taxonomy pages), go to the specific term and keep your mouse on the edit link. In the bottom left there will be a grey block which will hold the term id amongs other info. You can also create an extra column in your backend taxonomy ( category, tag or custom taxonomy ) pages to display the term id. There are a couple of good tutorials about this subject. You can also do a var_dump() of the the result from functions like get_terms() to find the relevant info from a specific term

To conclude, term ids within a specific install should always be 99.999% reliable, a term id does not change, it stays the same unless it is altered by the user himself via custom SQL queries or a custom function capable of altering the term id field, a plugin or a theme using such functionalities or if a term is deleted and recreated

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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