Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.
            $current_term = $wp_query->queried_object->name;
            $current_term_id = $wp_query->queried_object->ID;

            <hgroup class="section-heading wrapper">
                <h1><?php echo $current_term; ?></h1>
                <h3><?php echo category_description( $current_term_id ); ?></h3>

This works fine but the $current_term_id variable throws a warning …

Notice: Undefined property: stdClass::$ID in /Users/my/htdocs/wr/wp-content/themes/wr/taxonomy-event_type.php on line 12

Any ideas what I'm doing wrong here or what's the real property for the ID of the current term?

share|improve this question

2 Answers 2

up vote 4 down vote accepted

I faced the exact same problem for days and then found this! Use the function $wp_query->get_queried_object_id(). Check this for more details.

share|improve this answer

There's also a wrapper for this function get_queried_object_id(). It calls all parts like global $wp_query by itself.


Always use the most low level API, until you're forced to do otherwise.

The definition of API by the (current) wikipedia article is like the following

An application programming interface (API) is a specification intended to be used as an interface by software components to communicate with each other.

This means, that it was written to communicate with core internals and your theme or plugin.


Because of one easy reason: A wrapping API allows cores internals to transform, while still staying compatible with whatever you throw in as arguments. A wrapper function can add backwards compatibility where a core class/object may not.

It also shortens your code, makes it more readable and allows you to focus on what needs to be done by your code.

share|improve this answer

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.