Error with multiple get_the_terms
-
Given:
I have a post in a CPT with 3 custom taxonomies.Goal:
Output the single term from each of the taxonomies for the post.Issue:
Some variables are empty IF I use get_the_terms more than once.This code works:
$terms = get_the_terms( $post->ID , array( 'property_position') ); foreach ( $terms as $term ) { $position = $terms[0]->name; }
This code works:
$type_terms = get_the_terms( $post->ID , array( 'property_type') ); foreach ( $type_terms as $term ) { $type = $term->name; }
But this code does not work – $type is not assigned a variable.
$terms = get_the_terms( $post->ID , array( 'property_position') ); foreach ( $terms as $term ) { $position = $terms[0]->name; } $type_terms = get_the_terms( $post->ID , array( 'property_type') ); foreach ( $type_terms as $term ) { $type = $term->name; }
Any idea what the issue is?
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Error with multiple get_the_terms’ is closed to new replies.