Support

Account

Home Forums General Issues Get taxonomy term by ID

Solving

Get taxonomy term by ID

  • Hello,

    I have a custom taxonomy.

    When with single.php I try to output the custom taxonomy with:
    <?php the_field(‘arrondissement’, $term); ?>

    It returns the ID. How to I get the actual term to show?

    Thx!

  • What is the slug of your custom taxonomy?

    
    $taxonomy = 'your-taxonomy-slug'
    the_field('arrondissement', $taxonomy.'_'.$term->term_id);
    
  • It’s “ville”

    Doing so, output nothing though:

    $taxonomy = ‘ville’;
    the_field(‘arrondissement’, $taxonomy.’_’.$term->term_id);

  • I thought you were looking for how to get a custom field from a custom taxonomy, but I read it again and you say single.php, so now I’m a bit confused.

    What is the field type and where is the field group shown?
    Is the field group on posts?

  • Hello again đŸ™‚

    So I’m within the loop to get the content of a post, on single.php.

    This post has a custom field which is from a custom taxonomy. The custom taxonomy is “ville” and the custom field is “arrondissement”.

    I manage to get the ID of the term. But I would like to output the name of it, not the ID.

    <?php the_field(‘arrondissement’, $term); ?>

  • I’m still not really sure I’m understanding what you mean. Tell if this is correct.

    1) You have a single post of some kind. For this post you have taxonomy set up and you select a term in this taxonomy for your post. Do you want to show a custom field from this term?

    2) You have a post with a Taxonomy Field and you want to show the name of the Term selected in this field.

    Something else? Sorry, I’m just not getting the relationship between the post and what you want to display.

Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘Get taxonomy term by ID’ is closed to new replies.