Support

Account

Home Forums Front-end Issues Displaying fields from a cloned group inside a group

Solving

Displaying fields from a cloned group inside a group

  • Hi,

    I have a group and inside that group I have a cloned group field.

    How do I show the contents of the cloned group?

    Here is my code

    <?php 
    //vars
    $event = get_field('events');
    $event = get_field('address');
    
     ?>
    
    <div id="event-wrapper" itemscope itemtype="http://schema.org/Event">
    <h3>Event details</h3>
    <div><strong>Event name:</strong><span itemprop="name"> <?php echo $event['name']; ?></span> </div>
    <div><strong>Start date:</strong><span itemprop="startDate"> <?php echo $event['start_date']; ?></span> </div>
    <div><strong>About:</strong><span itemprop="description"> <?php echo $event['description']; ?></span></div>
    <div><strong>Who will like this event?:</strong><span itemprop="audience"> <?php echo $event['audience']; ?></span></div>
    <div itemprop="location" itemscope itemtype="http://schema.org/Place"><strong>Venue:</strong><span itemprop="name"> <?php echo $event['venue']; ?></span></div>
    
    	<div id="address" itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">
    		<strong>Address: </strong><span itemprop="streetAddress"><?php echo $address['street_address']; ?></span>, <span itemprop="addressLocality"> <?php echo $address['city']; ?></span>, <span itemprop="addressRegion"><?php echo $address['state']; ?></span>, <span itemprop="addressCountry"><?php echo $address['country']; ?></span>
    	</div>
    
    </div>

    The main groups name is “events” The cloned group underneath this group is “location” whoch has address fields cloned. I am trying to retrive the address field with $address variable. (that’s what it was originally.) But i have alsoe tried retiving the location field a stack of other combos and get no result

    My settings for the cloned groups are currently here http://prntscr.com/h5jtxe

    Can i get a hand please. I have spent hours on this and my head may explode.

    Thanks

  • Hi,

    first there seems to be a wrong declaration of the vars in your code:

    <?php 
    //vars
    $event = get_field('events');
    $event = get_field('address'); // should be $address ?

    Then if you want to get the cloned fields, you simply call it by field name to get an array of subfields OR by using the prefix for each field (see your settings screenshot => you enabled this option):

    $location = get_field('location');
    <div id="address" itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">
    		<strong>Address: </strong><span itemprop="streetAddress"><?php echo $location['street_address']; ?></span>, <span itemprop="addressLocality"> <?php echo $location['city']; ?></span>, <span itemprop="addressRegion"><?php echo $location['state']; ?></span>, <span itemprop="addressCountry"><?php echo $location['country']; ?></span>
    	</div>

    Example for getting seperate subfields:

    
    $location_street_address = get_field('location_street_address');
    $location_city = get_field('location_city');
    $location_state = get_field('location_state');
    $location_country = get_field('location_country');
    
    <div id="address" itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">
    		<strong>Address: </strong><span itemprop="streetAddress"><?php echo $location_street_address; ?></span>, <span itemprop="addressLocality"> <?php echo $location_city; ?></span>, <span itemprop="addressRegion"><?php echo $location_state; ?></span>, <span itemprop="addressCountry"><?php echo $location_country; ?></span>
    	</div>
  • Thanks for the reply

    Yes there was a typo on that var.

    Unfortunately, I am still stuck on this. I have copied your code in and still can’t get a result.

    I can see stuff in an array if I call $event[‘location’] but I can’t get any of it out when i try and populate the $location variable.

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

You must be logged in to reply to this topic.