Home › Forums › Add-ons › Gallery Field › View gallery image taxonomy in taxonomy custom page
Hi,
I created a custom field “carousel_slider_quarzite” type ACF Gallery in term of custom taxonomy “collections.”
In the category “Quartzite” taxonomy of “collections” appears “carousel_slider_quarzite” field with the images in my gallery.
This gallery should be shown on the “taxonomy-collection-quarzite.php” but something wrong.
CODE
<?php
$images = get_field('carousel_slider_quarzite');
if( $images ): ?>
<ul>
<?php foreach( $images as $image ): ?>
<li>
<a href="<?php echo $image['url']; ?>">
<img src="<?php echo $image['sizes']['thumbnail']; ?>" alt="<?php echo $image['alt']; ?>" />
</a>
<p><?php echo $image['caption']; ?></p>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
the custom field gallery, present in the category “quartzite” must be shown in the template category page. You can help me?
Sorry for my bad English
Thank you
When getting values from a taxonomy term you must supply the correct post id. See the “Get a value from other places” section of get_field() https://www.advancedcustomfields.com/resources/get_field/
<?php
$queried_object = get_queried_object();
$post_id = $queried_object->taxonomy.'_'.$queried_object->term_id;
$images = get_field('carousel_slider_quarzite', $post_id);
...
Thank you. and if I were to draw a field image “cover_collezione” in taxonomy custom “collezione” – post type “prodotto” in a page of my wordpress template?
see custom fields image of a post type category in a page template? excuse my English
You will need to get the category that the post is in and then get the field from that category. Take a look at https://codex.wordpress.org/Function_Reference/wp_get_post_terms or https://developer.wordpress.org/reference/functions/wp_get_post_categories/.
You must be logged in to reply to this topic.
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!
Plugin boilerplates can do some of the heavy lifting during initial development. We look at four options to speed up your plugin creation. https://t.co/ZtMsdBxAHw
— Advanced Custom Fields (@wp_acf) June 5, 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.