Home Forums General Issues Display Custom Taxonomy Fields on CPT


Display Custom Taxonomy Fields on CPT

  • So here is my scenario. I’d love some help getting my brain unstuck. I have a CPT and a Taxonomy. That taxonomy has custom fields. I’m trying to display the custom fields from the taxonomy on the CPT.

    An example. I have a business directory (CPT), each business has an owner (TAX). On the business listing, I want to pull in the owner information.

    I’m unsure on how to query to get this information correctly.

  • The first thing you need to do is get the term in the taxonomy that the post is in

    $terms = get_object_terms($post->ID, 'TAXONOMY SLUG HERE');

    this will return an array of terms that the post is in, assuming there is only one

    $term = $terms[0];

    now you can use this to get the fields from the term

    $value = get_field('field on term/taxonomy', 'term_'.$term->term_id;);
  • This reply has been marked as private.
  • Sorry, that should be wp_get_object_terms()' and there is an extra;` probably causing an error in the last bit of code.

    But this is basically what you need to do. To get the field from the term/taxonomy you need to provide ACF with the right $post_id value. See:

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

The topic ‘Display Custom Taxonomy Fields on CPT’ is closed to new replies.