Support

Account

Home Forums Front-end Issues advanced custom fields checkbox and gallery

Helping

advanced custom fields checkbox and gallery

  • I’m working with advanced custom fields to make a field that has and option that lets you check the checkbox field to activate the gallery field to add it to any page when every you checkbox.

    My issue is that the checkbox field says that it Enable in front-end of the website. But Image gallery field does want to show up do I have to do anything in the code to get this work correctly.

    This is right how display advanced custom fields code or do I have to combine them together can explain it to, please:

    <!-- Slider Here-->
    <?php
    
    $images = get_field('gallery');
    $activate_carousel_array = get_field( 'activate_carousel' );
    
      if( $images, $activate_carousel_array ):
      foreach ( $activate_carousel_array as $activate_carousel_item ):
    	 	echo $activate_carousel_item;
    	endforeach;
    ?>
        <div class="cycle-slideshow">
              <span class="cycle-pager"></span>
              <?php foreach( $images as $image ): ?>
                  <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
              <?php endforeach; ?>
    
              <?php foreach( $images as $image ): ?>
                  <img src="<?php echo $image['sizes']['thumbnail']; ?>" alt="<?php echo $image['alt']; ?>" />
              <?php endforeach; ?>
        </div>
    <?php endif; ?>
    <!-- End Slider Here-->
    
  • I’m assuming from your question that the “gallery” is not created on the page in question and is created somewhere else since checking the field will let you add it to any page. If this is the case then you need to supply ACF with the post ID of where the gallery is stored, whether that be another post or on an options page.

    
    $images = get_field('gallery', $post_id);
    

    For more information see the documentation for get field https://www.advancedcustomfields.com/resources/get_field/, especially the part about getting a value from different places.

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

The topic ‘advanced custom fields checkbox and gallery’ is closed to new replies.