Hi,
i am trying for several days to solve one problem in wordpress. And i really give up 🙂
I hope somebody can help.
<div id="research-slider">
<?php
$custom_terms = get_terms('areasofresearch');
foreach($custom_terms as $custom_term) {
wp_reset_query();
$args = array('post_type' => 'researchareas',
'tax_query' => array(
array(
'taxonomy' => 'areasofresearch',
'field' => 'slug',
'terms' => $custom_term->slug,
),
),
);
$loop = new WP_Query($args);
if($loop->have_posts()) { ?>
<div class="research-slide">
<div class="research-box">
<img src="NEED-THIS-URL" alt="" class="img-responsive">
<div class="research-caption">
<span class="title">Areas of Research</span>
<ul>
<?php while($loop->have_posts()) : $loop->the_post(); ?>
<li><a href="<?php echo get_permalink(); ?>"><?php the_title(''); ?></a></li>
<?php
endwhile; ?>
</ul>
</div>
<!-- // capotion -->
<span class="open-research"><?php echo $custom_term->name ?></span>
</div>
<!-- // box -->
</div>
<!-- // slide -->
<?php
}
}
?>
So i get nice list of categories along with all posts form those categories in slider. That works perfectly. But i need to get featured image that i set as a field on taxonomy. How can i get value from that field and display it here
<img src="NEED-THIS-URL" alt="" />
Is your field set to return the URL? or the object?
// ACF < 5.5.0
<img src="<?php the_field('image_field_name', $custom_term->taxonomy.'_'.$ $custom_term->term_id); ?>" alt="" class="img-responsive">
// ACF >= 5.5.0
<img src="<?php the_field('image_field_name', 'term_'.$custom_term->term_id); ?>" alt="" class="img-responsive">
See https://www.advancedcustomfields.com/resources/get-values-from-a-taxonomy-term/
If you are returning a image object/array instead of the url then see https://www.advancedcustomfields.com/resources/image/ for information on showing image fields.
Mate u saved my life 🙂 Any solution for image id instead of URL ?
If you’re returning an image ID value then you need to get the URL of the image using https://developer.wordpress.org/reference/functions/wp_get_attachment_image_src/ as described under Basic display (ID) here https://www.advancedcustomfields.com/resources/image/
The topic ‘Taxonomy / terms and acf value’ is closed to new replies.
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.