Displaying Nested Fields that also include Cloneable Groups

Support MB Views Displaying Nested Fields that also include Cloneable Groups

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #29050
    @mindspark@mindspark
    Participant

    I have a pretty complex data collection form and I'm trying to build a view to display deeply nested fields.

    I have a string of nested Group fields in the form setup like this:

    A. Cloneable Group 'Areas' > A.B. Cloneable Group 'Supervisor Zones' > A.C Cloneable Group 'Guards' > A.D Cloneable Group 'Locations' > User field set to multiple.

    See a visual of the form here: https://snipboard.io/k09q7D.jpg

    I'm trying to display info on the front end using the Views addon and I can't figure out how to display the 'User field set to multiple'. I'm assuming this requires several steps but I don't understand the instructions more than below.

    Only using this doesn't work:

    {% for item in clone.guard %}
    {{ item.display_name }}
    {% endfor %}

    HOW DO I NEST THESE ITEMS INTO A STATEMENT? All I need to display is the group of Users that are listed in the last field in this sequence.

    {% for post in query.posts %}
    INSERT POST FIELDS HERE
        
    {% for clone in post.areas %}
    INSERT SUB-FIELDS HERE
    {% endfor %}    
                        
    {% for clone in clone.groups %}
    INSERT SUB-FIELDS HERE
    {% endfor %}
                        
    {% for clone in clone.guards %}
    INSERT SUB-FIELDS HERE
    {% endfor %}
                        
    {% for item in clone.guard %}
    {{ item.display_name }}
    {% endfor %}    
                        
    {% endfor %}
    #29062
    Long NguyenLong Nguyen
    Moderator

    Hi,

    It's a very complicated group, to show the user info in that group you need more for loops. Each cloneable group will need 2 loops, one for cloneable, one for the subfields. For example, I have a field group

    function your_prefix_function_name( $meta_boxes ) {
        $prefix = '';
    
        $meta_boxes[] = [
            'title'  => __( 'Post Meta', 'your-text-domain' ),
            'id'     => 'post-meta',
            'fields' => [
                [
                    'name'   => __( 'Areas', 'your-text-domain' ),
                    'id'     => $prefix . 'areas',
                    'type'   => 'group',
                    'clone'  => true,
                    'fields' => [
                        [
                            'name'   => __( 'Zones', 'your-text-domain' ),
                            'id'     => $prefix . 'zones',
                            'type'   => 'group',
                            'clone'  => true,
                            'fields' => [
                                [
                                    'name'   => __( 'Guards', 'your-text-domain' ),
                                    'id'     => $prefix . 'guards',
                                    'type'   => 'group',
                                    'clone'  => true,
                                    'fields' => [
                                        [
                                            'name'   => __( 'Locations', 'your-text-domain' ),
                                            'id'     => $prefix . 'locations',
                                            'type'   => 'group',
                                            'clone'  => true,
                                            'fields' => [
                                                [
                                                    'name'       => __( 'User', 'your-text-domain' ),
                                                    'id'         => $prefix . 'user',
                                                    'type'       => 'user',
                                                    'field_type' => 'select_advanced',
                                                    'multiple'        => true
                                                ],
                                            ],
                                        ],
                                    ],
                                ],
                            ],
                        ],
                    ],
                ],
            ],
        ];
    
        return $meta_boxes;
    }

    the view code to get user info is

    {% for clone_areas in post.areas %}
        {% for clone_zones in clone_areas %}
            {% for zone in clone_zones %}
                {% for clone_guards in zone %}
                    {% for guard in clone_guards %} 
                        {% for clone_locations in guard %}
                            {% for location in clone_locations %}
                                {% for users in location %}
                                    {% for user in users %}
                                        {{user.display_name}}       
                                    {% endfor %}
                                {% endfor %}
                            {% endfor %}
                        {% endfor %}
                    {% endfor %}    
                {% endfor %}    
            {% endfor %}
        {% endfor %}
    {% endfor %}

    Hope that makes sense.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.