Home › Forums › Backend Issues (wp-admin) › update_sub_field doesn't work
Hi there!
Can someone tell me why update_sub_field doesn’t work. I got correct value for get_sub_field in the same loop, and correctly calculated $newPrice. But update_sub_field still doesn’t work.
Whan I’am doing wrong?
Here is my code:
if ($r->have_posts()) :
while ( $r->have_posts() ) : $r->the_post();
if(have_rows('object_additional')) {
while(have_rows('object_additional')) {
the_row();
//$projectSquareAll = get_sub_field('object_add_2');
$projectSquare = get_sub_field('object_add_1');
$projecFloor = get_sub_field('object_add_8');
}
}
if(have_rows('object_main')) {
while(have_rows('object_main')) {
the_row();
$projectPrice = get_sub_field('object_price');
error_log(print_r('---------------', true));
error_log(print_r('Проект '.get_the_title(), true));
//от 50 до 100м2
if (($projectSquare >= 50) && ($projectSquare <= 100) && ($projecFloor[0] == '1 этаж')) {
$priceForMeter = strtok($table['data'][1][1], 'тг');
$newPrice = $priceForMeter * $projectSquare;
update_sub_field('object_price', $newPrice);
//error_log(print_r($projectSquare, true));
} elseif (($projectSquare >= 50) && ($projectSquare <= 100) && ($projecFloor[0] == '2 этажа')) {
$priceForMeter = strtok($table['data'][2][1], 'тг');
$newPrice = $priceForMeter * $projectSquare;
update_sub_field('object_price', $newPrice);
}
//от 100 до 150м2
if (($projectSquare > 100) && ($projectSquare <= 150) && ($projecFloor[0] == '1 этаж')) {
$priceForMeter = strtok($table['data'][1][2], 'тг');
$newPrice = $priceForMeter * $projectSquare;
update_sub_field('object_price', $newPrice);
//error_log(print_r($projectSquare, true));
} elseif (($projectSquare > 100) && ($projectSquare <= 150) && ($projecFloor[0] == '2 этажа')) {
$priceForMeter = strtok($table['data'][2][2], 'тг');
$newPrice = $priceForMeter * $projectSquare;
update_sub_field('object_price', $newPrice);
}
//от 150 до 200м2
if (($projectSquare > 150) && ($projectSquare <= 200) && ($projecFloor[0] == '1 этаж')) {
$priceForMeter = strtok($table['data'][1][3], 'тг');
$newPrice = $priceForMeter * $projectSquare;
update_sub_field('object_price', $newPrice);
//error_log(print_r($projectSquare, true));
} elseif (($projectSquare > 150) && ($projectSquare <= 200) && ($projecFloor[0] == '2 этажа')) {
$priceForMeter = strtok($table['data'][2][3], 'тг');
$newPrice = $priceForMeter * $projectSquare;
update_sub_field('object_price', $newPrice);
}
//от 200 до 400м2
if (($projectSquare > 200) && ($projectSquare <= 400) && ($projecFloor[0] == '1 этаж')) {
$priceForMeter = strtok($table['data'][1][4], 'тг');
$newPrice = $priceForMeter * $projectSquare;
update_sub_field('object_price', $newPrice);
//error_log(print_r($projectSquare, true));
} elseif (($projectSquare > 200) && ($projectSquare <= 400) && ($projecFloor[0] == '2 этажа')) {
$priceForMeter = strtok($table['data'][2][4], 'тг');
$newPrice = $priceForMeter * $projectSquare;
update_sub_field('object_price', $newPrice);
}
//от 400м2
if (($projectSquare > 400) && ($projecFloor[0] == '1 этаж')) {
$priceForMeter = strtok($table['data'][1][5], 'тг');
$newPrice = $priceForMeter * $projectSquare;
update_sub_field('object_price', $newPrice);
//error_log(print_r($projectSquare, true));
} elseif (($projectSquare > 400) && ($projecFloor[0] == '2 этажа')) {
$priceForMeter = strtok($table['data'][2][5], 'тг');
$newPrice = $priceForMeter * $projectSquare;
update_sub_field('object_price', $newPrice);
}
//Если данные не заданы
if (((!$projectSquare) && (!$projecFloor[0])) || ((!$projectSquare) && ($projecFloor[0])) ||
(($projectSquare) && (!$projecFloor[0]))) {
}
//$res = return update_sub_field('object_price', $newPrice);
error_log(print_r('---------------', true));
}
}
endwhile;
wp_reset_postdata();
endif;
Thanks for advice
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.