Home › Forums › General Issues › WordPress Advanced Custom field get_field_object('field_name') don't work › Reply To: WordPress Advanced Custom field get_field_object('field_name') don't work
It looks like you are using a text field for the hair_color field rather than a select/option field.
So try any of these:
<?php
$queried_object = get_queried_object();
$taxonomy = $queried_object->taxonomy;
$term_id = $queried_object->term_id;
$hair_color = get_field('hair_color', $taxonomy . '_' . $term_id);
echo $hair_color;
?>
<?php
global $post;
$taxonomy = "someting";
$terms = get_the_terms($post->ID, $taxonomy);
if( !empty($terms) )
{
$term = array_pop($terms);
$custom_field = get_field('hair_color', $taxonomy . '_' . $term->term_id );
// do something with $custom_field
}
?>
See this example for more info: http://www.advancedcustomfields.com/resources/how-to/how-to-get-values-from-a-taxonomy-term/
If you do want to use a Radio Button field type and have them choose from a list of hair colors, then this might work too (I think):
<?php
$field = get_field_object('hair_color', $taxonomy . '_' . $term->term_id);
$value = get_field('hair_color');
$label = $field['choices'][ $value ];
echo '<p>' . $label . '</p>' ;
Probably didn’t work before due to being text field rather than select/radio field and the $taxonomy value not being defined, although not sure…
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!
Accordions are a great way to group related information while allowing users to interactively show and hide content. In this video, Damon Cook goes in-depth on how to create an accessible accordion block using ACF PRO’s Repeater field.https://t.co/RXT0g25akN
— Advanced Custom Fields (@wp_acf) March 2, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.