TransWikia.com

Creating a checklist with ACF and I cannot figure out how to add all iterations to an array that I'm creating

WordPress Development Asked by Hexen on December 17, 2021

Ok so I have this code on my website and I am trying to understand fully what is happening.

            <?php if( have_rows('comparison_chart') ): ?>
                <?php $feature_matrix = array(); ?>
                <?php $available_tiers = array(
                    'Learning Experience Platform' => 'learning_experience_platform', 
                    'Learning Management System' => 'learning_management_system'
                ); ?>
                <?php while( have_rows('comparison_chart') ): the_row(); ?>
                    <?php $feature = get_sub_field('feature'); ?>
                    <?php $tiers = get_sub_field('tiers'); ?>
                    <?php $info = get_sub_field('feature_info'); ?>
                    <?php foreach ($available_tiers as $tier => $slug) {
                        if (in_array($tier, $tiers)){
                            $feature_matrix['Tiers'][$tier][] = $feature;

                        }
                    } ?>
                    <?php $feature_matrix['Features'][$feature] = $tiers; ?>
                <?php endwhile; ?>
            <?php endif; ?>

The reason I am trying to understand what is going on is because I know there is an array created called feature_matrix and it looks like it’s adding these sub field to the array and what I need to do is add the feature_info sub field to that array also so I can pull it for each array and use it on the website. Below the code there is this code which pulls each feature and tier.

                 <?php foreach ($feature_matrix['Features'] as $feature => $tier): ?>
                        <?php $tiers = $feature_matrix['Features'][$feature]; ?>
                        <div class="row desktop-features">
                            <div class="col-md-6 features">
                                <?php echo $feature; ?><span class="caret">⌵</span>
                            </div>
                            <?php foreach ($available_tiers as $tier => $slug): ?>
                                <div class="col-xs-12 col-md-3 marker">
                                    <?php if (in_array($tier, $tiers)): ?>
                                        <i class="icon-check2"></i>
                                    <?php endif; ?>
                                </div>
                            <?php endforeach; ?>
                        </div>
                            <div class="col-xs-12 col-md-6 feature-info">
                                <?php echo $info; ?>
                            </div>
                            <div class="clearfix"></div>
                    <?php endforeach; ?>

You can see I am trying to pull the info variable but it keeps pulling only the last iteration of the array. How can I get it to pull each iteration of the array for each single one?

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP