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

I have created a custom taxonomy "Birthday" within which i have created various dates like "December-12", "April-15"

How to get the term_id of the "December-12" by a query.


share|improve this question
You'll want to create a WP_Query and use tax_query -- If you a little more direction I can help you write the query. However I'm not sure your final uses for this so I may not be able to answer it completely without further input. – David Mar 25 '12 at 20:27
To use with the below function: $users = get_objects_in_term( $term_id, $term->taxonomy ); I want to get the $term_id ( id of "December-12" created under "Birthday") rather than using $term_id = get_queried_object_id(); Thanks. – Vijay Mar 25 '12 at 20:31

You can use the get_term_by function. This allows you to obtain a term (from a given taxonomy) by its slug or name (or id). The returned term object contains the term's ID.

For example:

$term =get_term_by( 'name', 'December-12', 'Birthday');
$term_id = $term->term_id;

If 'December-12' is the slug, rather than the name, of the term, simply replace 'name' with 'slug'.

share|improve this answer
Thanks, i also figured out another way, i am not sure if its a clean code thought.. :-) <?php $categories = get_categories(array( 'taxonomy' => 'birthday' )); foreach( $categories as $category ) { $category_name = $category->name; $category_id = $category->cat_ID; $todays_date = date("F-d"); if ($category_name == $todays_date) { $users = get_objects_in_term( $category_id, 'birthday' ); ?> – Vijay Mar 25 '12 at 21:19
That would do it - but its less efficient and my answer only takes two lines :D. Its also more complicated to read. – Stephen Harris Mar 25 '12 at 21:28

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.