Home › Forums › General Issues › Cannot update repeater field!
Hey Guys,
I want to update my repeater field which shows prices, old prices, links and shops. But my problem is, that I always get this, if I print the repeater:
array(1) { [0]=> array(11) { ["price"]=> bool(false) ["price_old"]=> bool(false) ["currency"]=> bool(false) ["price_hint"]=> string(0) "" ["price_hint_disable"]=> bool(false) ["portal"]=> string(0) "" ["artnr"]=> string(0) "" ["amazon_asin"]=> string(0) "" ["affilinet_id"]=> string(0) "" ["shop"]=> bool(false) ["link"]=> bool(false) } }
So, there is somewhere a error and the values I commit to the array, doesn’t get inserted right.
I already tried:
$product_shops_array = array(
array(
'price' => 100,
'price_old' => 10,
'link' => 'https://google.de',
'shop' => 2213
)
);
$pid = get_the_ID();
update_field('product_shops', $product_shops_array, $pid);
And I also tried this way:
$ad = array(
'price' => '100',
'price_old' => '10',
'currency' => 'euro',
'link' => 'https://google.de',
'shop' => '2213'
);
$adc = array(
'price' => '10',
'price_old' => '1',
'currency' => 'euro',
'link' => 'https://google.de',
'shop' => '2213'
);
$adcd = array(
'price' => '5',
'price_old' => '4',
'currency' => 'euro',
'link' => 'https://google.de',
'shop' => '2213'
);
array_push($product_shops_array, $ad);
array_push($product_shops_array, $adc);
array_push($product_shops_array, $adcd);
$pid = get_the_ID();
update_field('product_shops', $product_shops_array, $pid);
And I also tried this two ways without the '
at the field price
, price_old
and shop
. But they are also not working…
So, my question is, how can I update my repeater field product_shops
with new entries?
Greetings and Thank You!
You need to use the field keys when using update_field() instead of the field names. Using field names will only work when the values for a field already exist in the database and will not work correctly where they do not. update_field() is one of the functions in ACF that pretty much requires field keys in order to work 100% of the time.
I don’t know what you mean… Do you have an example for me?
You mean something like this?
array(2) {
[0]=>
array(6) {
["price"]=>
string(5) "19.98"
["price_old"]=>
string(5) "10.66"
["currency"]=>
string(4) "euro"
["portal"]=>
string(0) ""
["link"]=>
string(86) "https://de.gamesplanet.com/game/max-payne-double-pack-1-2-steam-key--1005-1?ref=gmkeys"
["shop"]=>
string(4) "9509"
}
[1]=>
array(6) {
["price"]=>
string(4) "7.99"
["price_old"]=>
string(4) "1.66"
["currency"]=>
string(4) "euro"
["portal"]=>
string(0) ""
["link"]=>
string(70) "https://de.gamesplanet.com/game/dracula-4-steam-key--1006-1?ref=gmkeys"
["shop"]=>
string(4) "9510"
}
}
sorry I didn’t get back to you sooner, your email got buried.
Anyway, you need to use the field keys. Look in the admin on the field group editor. If you don’t see the field keys set them to display under screen options.
When you construct your array you use the field keys in place of the names, it will look something like this
$array = array(
// nested array for each row
array(
// row 1
// element for each field
'field_123456' => 'value 1', // this key is the acf field key
'field_234567' => 'value 2',
// ... etc
),
array(
// row 1
// ... etc
),
// ... etc
);
and use the field key in update field
// use the field key of the repeater here
update_field('field_xyz120', $array, $id);
The topic ‘Cannot update repeater field!’ is closed to new replies.
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.