Home Forums ACF PRO Echo names of taxonomies of an array


Echo names of taxonomies of an array

  • Hi,

    I’m trying to echo the names of more than 1 taxonomy which is set in an array ($orty) of each specific post.
    The array now has for example 3 IDs of taxonomies inside. I want to find out the names of these specific taxonomy IDs and echo them in a row with | between them.

    I was able to get the IDs of the taxonomies and output them in a row
    $orty = get_field("acf-property-location", get_the_ID());
    when I used foreach afterwards.
    But finally I’ll need the names of the taxonomies in a row and not only the IDs.
    I thought about using foreach to echo the names of the taxonomies that are set in $orty

    foreach (get_field( $orty ) as $termy)
      echo $termy.'|';

    But sure this code is wrong. 😉
    Or should I better use something like get_the_terms?

    My PHP-skills aren’t the best, but I’m still learning, so please help me out and if possible explain me why I should code it different.

    Thanks for your help guys!

  • Is the field acf-property-location returning term objects or term IDs.

    If you want to echo the names of the terms then it would be easiest to return term objects.

    $orty = get_field("acf-property-location", get_the_ID());
    foreach (get_field( $orty ) as $termy) {
      echo termy->name,' | ';
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.