$wp_query->queried_object->ID throws warning: Undefined property

<?php 
    $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>
</hgroup>

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?

4 s
4

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.

Leave a Comment