Title: Duplicate Group with Magic Fields 1
Last modified: August 30, 2016

---

# Duplicate Group with Magic Fields 1

 *  Resolved Anonymous User 4309634
 * (@anonymized-4309634)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/duplicate-group-with-magic-fields-1/)
 * I’ve created a group which can be duplicated containing 2 fields which cannot
   be duplicated (WordPress 4.3.1 / Magic Fields 1.6.3.2)
 * I’m trying to output the values but I’m just getting a blank – no errors but 
   no data either.
 * This is my code:
 *     ```
       <?php
       $nearest_locations = get_group('nearest_locations');
       if($nearest_locations) {
       foreach($nearest_locations as $nearest_location){
       echo $nearest_location['nearest_locations_location_name'][1]."<br />";
       echo $nearest_location['nearest_locations_location_distance'][1]."<br />";
       }}
       ?>
       ```
   
 * I have read lots of threads on this and I don’t know what I’m doing wrong! Any
   help would be much appreciated 🙂
 * [https://wordpress.org/plugins/magic-fields/](https://wordpress.org/plugins/magic-fields/)

Viewing 1 replies (of 1 total)

 *  Thread Starter Anonymous User 4309634
 * (@anonymized-4309634)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/duplicate-group-with-magic-fields-1/#post-6821824)
 * I figured this out in the end:
 *     ```
       <?php
        // duplicate groups.
   
        // getGroupOrder us back an array of the order of groups
        // The parameter for this function is the name of a field belonging to the group
   
        $sites = getGroupOrder('nearest_locations_location_name');
        foreach($sites as $site){
        ?>
   
        <li class="<?php echo get('nearest_locations_indoor_session',$site); ?>">
        <?php
   
        // the second parameter of the function and get_image get is the index of the group to show
        $related_content = get('nearest_locations_location_link',$site);
        ?>
   
        <a href="<?php echo get_permalink($related_content); ?>">
   
        <?php
        echo get('nearest_locations_location_name',$site)."</a> (";
        echo get('nearest_locations_location_distance',$site).")";
        ?>
        </li>
        <?php  } ?>
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Duplicate Group with Magic Fields 1’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/magic-fields.svg)
 * [Magic Fields](https://wordpress.org/plugins/magic-fields/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/magic-fields/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/magic-fields/)
 * [Active Topics](https://wordpress.org/support/plugin/magic-fields/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/magic-fields/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/magic-fields/reviews/)

 * 1 reply
 * 1 participant
 * Last reply from: Anonymous User 4309634
 * Last activity: [10 years, 3 months ago](https://wordpress.org/support/topic/duplicate-group-with-magic-fields-1/#post-6821824)
 * Status: resolved