Support

Account

Home Forums Add-ons Gallery Field View gallery image taxonomy in taxonomy custom page

Solved

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?

  • I don’t understand your follow up question.

  • 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/.

Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘View gallery image taxonomy in taxonomy custom page’ is closed to new replies.