• Hi everbody,

    I like to output the ID of the current taxonomy ID I’m using. I’m looking for something like <?php the_category_ID(); ?>

    While searching via Google I found code examples like this:

    <?php $terms = get_the_terms( $post->ID , 'taxonomy-name' );
    if($terms) {
    	foreach( $terms as $term ) {
    		echo $term->term_id.'<br />';
    	}
    }
    ?>

    The problem is that I can’t set the ‘taxonomy-name’, because it’s an unordered list of posts with different taxonomies. So I need something, that WordPress uses automatically the taxonomy-name of the actual post.

    Can somebody helps me?

    Thank you!

    Greetings from Germany,
    Raisis

Viewing 1 replies (of 1 total)
  • you could do a $wpdb query like

    //get the IDs
    $taxonomy_IDs = $wpdb->get_col("SELECT term_taxonomy_id FROM $wpdb->term_relationships WHERE object_id = '".get_the_ID()."'");
    //output the IDs
    echo implode(',', $taxonomy_IDs);

    but you’d be doing that for EACH post.. and is a little server heavy

Viewing 1 replies (of 1 total)
  • The topic ‘Get ID of current taxonomy’ is closed to new replies.