В моих дополнительных настраиваемых полях у меня есть группа внутри группы.
Поля во внутренней группе предназначены для выбора частей блюд.Помимо первой строки в этой группе, формат будет точно таким же
Я написал код, который выводит название продукта и значениеассоциируется с каждым (умножается на другую переменную).
Помимо вывода их, в 5-й и 6-й строке есть оператор if.Они показывают, только если другая переменная $ feeds_per_day так же высока, как и номер еды.
Вот код ...
if( have_rows('zero') ):
?><div class="grid-50" style="float: left;"><table><tr><th colspan="2">Zero</th></tr><?php
while( have_rows('zero') ) : the_row(); ?>
<tr><td>Upon Waking</td><td><?php the_sub_field('upon_waking')?></td></tr>
<?php
if ( have_rows('meal_1') ){
while( have_rows('meal_1') ) {
the_row();
$protein_object = (get_sub_field_object('protein_select'));
$protein_value = get_sub_field('protein_select');
$protein_label = ($protein_object['choices'][$protein_value]);
$carb_object = (get_sub_field_object('carb_select'));
$carb_value = get_sub_field('carb_select');
$carb_label = ($carb_object['choices'][$carb_value]);
$fat_object = (get_sub_field_object('fat_select'));
$fat_value = get_sub_field('fat_select');
$fat_label = ($fat_object['choices'][$fat_value]);
$protein_amount = round($zero_protein_feed / $protein_value * 10) *10;
$fat_amount = round($zero_fat_feed / $fat_value * 10) *10 ;
?><tr><td>Meal 1</td><td><?php echo $protein_amount ?>g <?php echo $protein_label ?>, <?php echo $fat_amount ?>g <?php echo $fat_label ?></td></tr><?php } }
if ( have_rows('meal_2') ){
while( have_rows('meal_2') ) {
the_row();
$protein_object = (get_sub_field_object('protein_select'));
$protein_value = get_sub_field('protein_select');
$protein_label = ($protein_object['choices'][$protein_value]);
$carb_object = (get_sub_field_object('carb_select'));
$carb_value = get_sub_field('carb_select');
$carb_label = ($carb_object['choices'][$carb_value]);
$fat_object = (get_sub_field_object('fat_select'));
$fat_value = get_sub_field('fat_select');
$fat_label = ($fat_object['choices'][$fat_value]);
$protein_amount = round($zero_protein_feed / $protein_value * 10) * 10 ;
$fat_amount = round($zero_fat_feed / $fat_value * 10) * 10 ;
?><tr><td>Meal 2</td><td><?php echo $protein_amount ?>g <?php echo $protein_label ?>, <?php echo $fat_amount ?>g <?php echo $fat_label ?></td></tr><?php } }
if ( have_rows('meal_3') ){
while( have_rows('meal_3') ) {
the_row();
$protein_object = (get_sub_field_object('protein_select'));
$protein_value = get_sub_field('protein_select');
$protein_label = ($protein_object['choices'][$protein_value]);
$carb_object = (get_sub_field_object('carb_select'));
$carb_value = get_sub_field('carb_select');
$carb_label = ($carb_object['choices'][$carb_value]);
$fat_object = (get_sub_field_object('fat_select'));
$fat_value = get_sub_field('fat_select');
$fat_label = ($fat_object['choices'][$fat_value]);
$protein_amount = round($zero_protein_feed / $protein_value * 10) * 10 ;
$fat_amount = round($zero_fat_feed / $fat_value * 10) * 10 ;
?><tr><td>Meal 3</td><td><?php echo $protein_amount ?>g <?php echo $protein_label ?>, <?php echo $fat_amount ?>g <?php echo $fat_label ?></td></tr><?php } }
if ( have_rows('meal_4') ){
while( have_rows('meal_4') ) {
the_row();
$protein_object = (get_sub_field_object('protein_select'));
$protein_value = get_sub_field('protein_select');
$protein_label = ($protein_object['choices'][$protein_value]);
$carb_object = (get_sub_field_object('carb_select'));
$carb_value = get_sub_field('carb_select');
$carb_label = ($carb_object['choices'][$carb_value]);
$fat_object = (get_sub_field_object('fat_select'));
$fat_value = get_sub_field('fat_select');
$fat_label = ($fat_object['choices'][$fat_value]);
$protein_amount = round($zero_protein_feed / $protein_value * 10) * 10 ;
$fat_amount = round($zero_fat_feed / $fat_value * 10) * 10 ;
?><tr><td>Meal 4</td><td><?php echo $protein_amount ?>g <?php echo $protein_label ?>, <?php echo $fat_amount ?>g <?php echo $fat_label ?></td></tr><?php } }
if ( have_rows('meal_5') ){
while( have_rows('meal_5') ) {
the_row();
$protein_object = (get_sub_field_object('protein_select'));
$protein_value = get_sub_field('protein_select');
$protein_label = ($protein_object['choices'][$protein_value]);
$carb_object = (get_sub_field_object('carb_select'));
$carb_value = get_sub_field('carb_select');
$carb_label = ($carb_object['choices'][$carb_value]);
$fat_object = (get_sub_field_object('fat_select'));
$fat_value = get_sub_field('fat_select');
$fat_label = ($fat_object['choices'][$fat_value]);
$protein_amount = round($zero_protein_feed / $protein_value * 10) * 10 ;
$fat_amount = round($zero_fat_feed / $fat_value * 10) * 10 ;
if ($feeds_per_day > 4){
?><tr><td>Meal 5</td><td><?php echo $protein_amount ?>g <?php echo $protein_label ?>, <?php echo $fat_amount ?>g <?php echo $fat_label ?></td></tr><?php } }
}
if ( have_rows('meal_6') ){
while( have_rows('meal_6') ) {
the_row();
$protein_object = (get_sub_field_object('protein_select'));
$protein_value = get_sub_field('protein_select');
$protein_label = ($protein_object['choices'][$protein_value]);
$carb_object = (get_sub_field_object('carb_select'));
$carb_value = get_sub_field('carb_select');
$carb_label = ($carb_object['choices'][$carb_value]);
$fat_object = (get_sub_field_object('fat_select'));
$fat_value = get_sub_field('fat_select');
$fat_label = ($fat_object['choices'][$fat_value]);
$protein_amount = round($zero_protein_feed / $protein_value * 10) * 10 ;
$fat_amount = round($zero_fat_feed / $fat_value * 10) * 10 ;
if ($feeds_per_day > 5){
?><tr><td>Meal 6</td><td><?php echo $protein_amount ?>g <?php echo $protein_label ?>, <?php echo $fat_amount ?>g <?php echo $fat_label ?></td></tr><?php } }
}
endwhile;
?></table></div><?php
endif;
... кроме первой строки, яповторяя много одного и того же кода. Есть ли способ циклически проходить по всем полям и применять один формат, если поле имеет значение "Upon_Waking", и другой формат, если нет?