Get Custom Taxonomy ID within loop

You can try this function get_term_by($field, $value, $taxonomy, $output, $filter ) or

$termID = [];
$terms = get_the_terms($post->ID, 'taxonomy');
foreach ($terms as $term) {
    $termID[] = $term->term_id;
}

or get_queried_object_id()

Leave a Comment