Hey guys,
I am trying to update a select field in a repeater, based on another ACF field.
I have the following so far, which works, but I need to check if the value exists already to avoid duplicates. Can anyone point out how to correct my code?
<?php
$update_me = get_field('website');
$field_key = "field_55f2e2b76d08e";
$value = get_field($field_key);
$value[] = array("field_55f2e2dc6d08f" => "website", "field_55f2e3256d090" => $update_me);
if($value != 'website') {
update_field( $field_key, $value);
}
?>
Thanks so much!
I’m not sure I understand what you mean by but I need to check if the value exists already to avoid duplicates
Do you mean that you want to see if someone has selected the value already for another post?
Hey there John,
Let me try explain a bit better:
I have the following field:
Website
and the following two SELECT fields in a repeater:
TYPE: (phone, email, website etc)
VALUE:
When I open the page, I need to check whether the choice “TYPE: Website” exists and has a VALUE. if it does, do nothing. If it doesn’t, update it using the Website field. Otherwise the repeater SELECT field ends up with duplicate website values.
Hope that makes more sense?
Also, is it possible to delete a choice if it is empty? ie, if a repeater has:
Phone: XXX XXX XXXX
Cellphone: XXX XXX XXXX
Cellphone:
Email: [email protected]Delete the second cellphone choice when opening the page?
If it’s all part of the same repeater, maybe.
you can create an acf/load_value filter on the repeater field http://www.advancedcustomfields.com/resources/acfload_value/
In this filter you it would be possible to remove duplicate values. The value for the repeater will be a multidimensional array that looks something like this:
$value = array(
// there will be a nested array for each row
array(
// each field in the row will have a value
'type' => 'website',
'value' => 'http://www.website.com/'
)
)
You could loop through the array, record what’s in each row and delete the duplicates, you could also get the value of another field to check to see it that is duplicated as well. At least in theory this might do what you need.
The topic ‘Update Repeater SELECT 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.