How do I access a single term from a post?

Question

I need help accessing a specific term from a custom taxonomy.

I am getting the terms with

 $terms = wp_get_post_terms($post->ID, 'mytax', array("fields" => "all"));

If I print_r($terms) this is what I get:

Array ( 
    [0] => WP_Term Object ( 
        [term_id] => 30 
        [name] => Term1 
        [slug] => term1 
        [term_group] => 0 
        [term_taxonomy_id] => 30 
        [taxonomy] => mytax 
        [description] => 
        [parent] => 0 
        [count] => 78 
        [filter] => raw 
    ) 
    [1] => WP_Term Object ( 
        [term_id] => 32 
        [name] => Term2 
        [slug] => term2 
        [term_group] => 0 
        [term_taxonomy_id] => 32 
        [taxonomy] => mytax 
        [description] => 
        [parent] => 30 
        [count] => 44 
        [filter] => raw 
    ) 
)

How do I extract the ID for Term1 out of this array?

0
Philipp K 2 months 0 Answers 10 views 0

Leave an answer