Last active
February 17, 2021 00:18
-
-
Save frankyonnetti/43ff57a638ee05798d32943943f6bfd4 to your computer and use it in GitHub Desktop.
WordPress - ACF for each array #wordpress #acf #array #foreach
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php if (have_rows('price_table_row_with_columns')): ?> | |
| <?php while (have_rows('price_table_row_with_columns')): the_row(); | |
| $row_columns = array( | |
| get_sub_field('row_column_2'), | |
| get_sub_field('row_column_3'), | |
| get_sub_field('row_column_4')); | |
| ?> | |
| <div class="pricing-table-row"> | |
| <?php $column_count = 1; ?> | |
| <?php foreach ($row_columns as $row_column): ?> | |
| <?php $i = $column_count++; ?> | |
| <div class="column column-<?php echo $i; ?>"> | |
| <?php if ($row_column): ?> | |
| <span class="price"><?php echo $row_column; ?></span> | |
| <?php endif; ?> | |
| </div> | |
| <?php endforeach; ?> | |
| </div><!-- /pricing-table-row --> | |
| <?php endwhile; ?> | |
| <?php endif; ?> | |
| // array_combine | |
| <?php if (have_rows('price_table_header_columns')): ?> | |
| <?php while (have_rows('price_table_header_columns')): the_row(); | |
| $price_table_header_columns = array( | |
| get_sub_field('price_table_header_column_1'), | |
| get_sub_field('price_table_header_column_2'), | |
| get_sub_field('price_table_header_column_3'), | |
| get_sub_field('price_table_header_column_4'), | |
| ); | |
| $price_table_header_columns_date = array( | |
| get_sub_field('price_table_header_column_1_date'), | |
| get_sub_field('price_table_header_column_2_date'), | |
| get_sub_field('price_table_header_column_3_date'), | |
| get_sub_field('price_table_header_column_4_date'), | |
| ); | |
| ?> | |
| <?php $column_count_header = 1; ?> | |
| <?php foreach (array_combine($price_table_header_columns, $price_table_header_columns_date) as $price_table_header_column => $price_table_header_column_date): ?> | |
| <?php $i = $column_count_header++; ?> | |
| <div class="column column-header-<?php echo $i; ?>"> | |
| <?php if ($price_table_header_column): ?> | |
| <div class="pricing-header"> | |
| <?php echo $price_table_header_column; ?> | |
| <?php if ($price_table_header_column_date): ?> | |
| <div class="pricing-header-date"> | |
| <?php echo $price_table_header_column_date; ?> | |
| </div> | |
| <?php endif; ?> | |
| </div> | |
| <?php endif; ?> | |
| </div> | |
| <?php endforeach; ?> | |
| <?php endwhile; ?> | |
| <?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment