Home › Forums › Front-end Issues › Returning Custom Field Values (including Taxonomy Terms) on Term archive pages › Reply To: Returning Custom Field Values (including Taxonomy Terms) on Term archive pages
@hube2: I’m able to now retrieve an array with:
<?php
$queried_object = get_queried_object();
$taxonomy = $queried_object->taxonomy;
$term_id = $queried_object->term_id;
$value = get_field( 'test_field', $taxonomy.'_'.$term_id);
if( $value ) {
echo $value;
} else {
echo 'empty';
}
?>
Why cant the_field() do what echo does here?
I retrieve an array when the custom field is text & get an error message when its a taxonomy term:
“Catchable fatal error: Object of class WP_Term could not be converted to string”
I also retrieve an array when the custom field is an image.
Looks like we now have to iterate through the string array in order to show the value; brings back the 2nd aspect of my question.
How do you best display the returned string(s)/array on a taxonomy term archive page:
-if ACF field value is text?
-if ACF field value is an image?
-if ACF field value is a single or multiple taxonomy terms?
-if I would like to display the term values as linkable vs non linkable?
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!
Are you building WordPress sites with ACF and @BeaverBuilder, and wanted to use your ACF Blocks in both the block editor and Beaver Builder?
— Advanced Custom Fields (@wp_acf) May 10, 2023
The BB team recently added support for using ACF Blocks in Beaver Builder. Check it out 👇https://t.co/UalEIa5aQi
© 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.