Home › Forums › General Issues › Field group at taxonomy does not work › Reply To: Field group at taxonomy does not work
Ok, I’ve done a bit of testing and I agree that something is not working as expected… until I figured out how to get taxonomy fields. I’ll try and lay this out so that you guys can tell me if I’m doing the right thing!
Steps to reproduce:
get_field()
I was unable to get the field data properly until realizing that I wasn’t calling the taxonomy field properly.
http://www.advancedcustomfields.com/resources/how-to/how-to-get-values-from-a-taxonomy-term/
So getting the field data looks like this (using @mdetoni’s taxonomy):
$terms = get_terms( 'audiocategorias', array( 'hide_empty'=>false ) );
foreach($terms as $term){
$field = get_field('ab_rolp', $term->taxonomy.'_'.$term->term_id)
echo '<pre>field: '.print_r( $field, true).'</pre>';
}
To get taxonomy fields, the post ID variable must start with taxonomyname_
, so in this case audiocategorias
, or in the example we pull it directly from the taxonomy term itself: $term->taxonomy.'_'
.
Does this help anyone or am I heading in the wrong direction?
Edit: @drift2’s example
$terms = get_terms( 'radioroom', array( 'hide_empty'=>false ) );
foreach($terms as $term){
$field = get_field('style_id', $term->taxonomy.'_'.$term->term_id)
echo '<pre>field: '.print_r( $field, true).'</pre>';
}
Note that in these examples we are using 'hide_empty'=>false
in order to force the retrieval of terms. This is required for a term to show up in our list if there aren’t any posts with this term selected.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.