Support

Account

Home Forums General Issues Display a Basic Field Group

Solved

Display a Basic Field Group

  • Hey all.
    I’m new to WP and am getting started with this nice plugin. I’m using it to make a simple column of images in a post. So I’ve made a field group with four image fields in it. What I need to return is all images within the field group.

    And help would be great

  • First off, have you read the documentation on image fields?

    http://www.advancedcustomfields.com/resources/field-types/image/

    Post a screenshot of your fields in their field group

  • Hey Mike.

    Yep I did. I guess my question is, if my field group ‘Gallery’ has 8 images in it, how do I display the entire group. I can of course display images by doing something simple like <img src="<?php the_field('image_1'); ?>" /> but I’m wanting to return the value of the gallery in a single query rather than having to add a number of image tags.

  • @mineisyours

    Ah, got it. Using the Repeater field or the Gallery field would be much easier to accomplish this.

    To accomplish what you want to accomplish, you would have to use the
    get_field_object() function.

    Let’s start off dumping everything and seeing what we are working with:

    <code>
    <pre><?php $fields = get_field_objects(); var_dump( $fields ); ?>
    </pre>
    </code>

    That will spit out the multi-dimentional array, in which you can just loop through it and get the data you need! You will need to do this within the WP loop, btw.

    Note: The return value for my image fields are set as image objects.

    
    <?php $fields = get_field_objects(); ?>
    		 
    		<?php if( $fields ): ?>
    			<?php foreach( $fields as $field ): ?>
    				<div><img src="<?php echo $field['value']["url"]; ?>" alt=""></div>
    			<?php endforeach; ?>
    		<?php endif; ?>
    
  • Hey Mike.
    Thanks mate. I hadn’t read that far on. I appreciate your help.

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

The topic ‘Display a Basic Field Group’ is closed to new replies.