In my day to day work, one of my jobs is to setup word-press themes for my clients. Yesterday, I was setting up and configuring a theme that shows latest post from each category in the middle column. The site was over an year old and there were a lot of categories accumulated over time.
Theme had an option where I can put all the categories that I don’t want to display. The theme developer saved time by no providing an interface to select / remove categories. the lazy developer just put a text box where I had to list unwanted categories in comma separated fashion.
Now the challenge for me here was to ask the client which categories they wish to exclude. But in order to do that, I had to provide them a list of all categories. I could simply go to category section of wordpress admin dashboard but catagory ids are not listed there. so I had to fire up phpMyAdmin and look for a solution in MySQL database of wordpress.
I found out that there are three tables.
WP-TERMS table contains all tags and categories and god knows what else.
In WP-TERM-TAXONOMY table, I found that all term ids got defined as tags or categories etc. so i have wrote following MySQL Query to list all categories with their category id and names.
MySQL Query to get Category IDs from WordPress DB
SELECT wp_terms.term_id, wp_terms.name,wp_term_taxonomy.taxonomy FROM wp_terms INNER JOIN wp_term_taxonomy ON wp_terms.term_id = wp_term_taxonomy.term_id WHERE wp_term_taxonomy.taxonomy = ‘category’
I have shared this here in case someone might need to accomplish the same task of listing all category ids in wordpress. I can be a place for my future reference as well. cheers folks.
You might also like
|MySQL vs. MS SQL Mostly people ask that what is the difference between MySQL and MS SQL. In this article I will explain...||Top 5 WordPress Virtual Appliance Downloads There are number of virtual appliances available for some one who is deep into wordpress blogging and...||Remove Date (Year/Month/Day) in WordPress Permalink URL with htaccess All you need is to go to wordpress dashboard. Go Settings -> Permalinks Select Custom Structure...||How to Fix Fatal Error after upgrade to WordPress 2.8 If you are like many of us using some plug-ins like nofollow links in post or Google analytics(these...|