Support

Account

Home Forums General Issues How do I show custom fields from tax on posts?

Solving

How do I show custom fields from tax on posts?

  • ACF provides an example that retrieves custom fields from a taxonomy and then displays it on an archive page such as category.php.

    https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/#example

    This approach doesn’t work for a single post. Does anyone have any advice on how to retrieve custom fields from a taxonomy and then display it on a single post?

  • You have to use wp_get_post_terms() or get_the_terms(). Both of these return an array of terms. Then you loop over the array to get values from the terms.

  • Thanks. I am using get_the_terms(). It is retrieving the values but I need to only retrieve a specific index from the array depending on the page. For example:

    – A person will see a page and then the name of an artist will appear.
    – This artist name is a tax term.
    – Only certain artist tax terms are used on specific pages.

    What is happening on my end right now is that the first index of the array is being shown (the first artist term). Is there a way to only show terms that are associated with the current single post?

  • The only reason get_the_terms should be returning more than one is if more than one is selected for that post. From the doc.

    
    get_the_terms( int|WP_Post $post, string $taxonomy )
    

    should only get the terms selected for the post in the specified taxonomy

  • Thanks for that clarification. I will look further into it.

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

You must be logged in to reply to this topic.