get_the_terms
-
I am trying to get the value from a custom taxonomy using get_the_terms. Seems like a simple thing but I havent been able to get it to work:
while ($query4->have_posts() ) : $query4->the_post(); if( has_term('' , 'orderIt1' )) { $theIDforordering2 = get_the_ID(); $firstRandArray = get_the_terms( $theIDforordering2, orderIt1 ); $secondRandArray = get_the_terms( $theIDforordering2, orderIt2 ); var_dump ($firstRandArray); var_dump ($firstRandArray['"name"']); } else {echo "";}
When I do var_dump for the $firstRand it comes back with this:
array(1) { [0]=> object(WP_Term)#3105 (11) { [“term_id”]=> int(32) [“name”]=> string(1) “1” [“slug”]=> string(1) “1” [“term_group”]=> int(0) [“term_taxonomy_id”]=> int(32) [“taxonomy”]=> string(8) “orderIt1” [“description”]=> string(0) “” [“parent”]=> int(0) [“count”]=> int(1) [“filter”]=> string(3) “raw” [“object_id”]=> int(188) } }
The custom tag for this post is “1”. So I guess it is under “name”. How do I access that and strip off the string(1) and the quotation marks?
I thought I might get it with $firstRandArray[‘”name”‘] or $firstRandArray[‘name’] or $firstRandArray->name but all return NULL.
- The topic ‘get_the_terms’ is closed to new replies.