Home › Forums › Backend Issues (wp-admin) › "get_field"/"get_fields" but with keys instead of names
This is the result I got from $_POST when saving a ACF repeater.
["field_5c8f3ed7718ef"]=>
array(4) {
[0]=>
array(2) {
["field_5c8f423a718f0"]=>
string(6) "ico-04"
["field_5c8f43e5076f7"]=>
string(3) "333"
}
[1]=>
array(2) {
["field_5c8f423a718f0"]=>
string(6) "ico-04"
["field_5c8f43e5076f7"]=>
string(3) "333"
}
[2]=>
array(2) {
["field_5c8f423a718f0"]=>
string(6) "ico-04"
["field_5c8f43e5076f7"]=>
string(6) "123123"
}
[3]=>
array(2) {
["field_5c8f423a718f0"]=>
string(6) "ico-04"
["field_5c8f43e5076f7"]=>
string(6) "123123"
}
}
Is it possible to produce this with an ACF function?
I managed to temporarily solve it by doing this:
$field_name = get_field_object($field['acf_mirror_field'])['name'];
$field_object = get_field_object($field_name, 'option');
$values = get_field($field_name, 'option');
if( have_rows($field_name) ){
echo " this is a repeater";
while( have_rows($field_name) ) { the_row();
foreach($field_object['value'] as $sub_key => $sub_field){
foreach($sub_field as $repeater_key => $repeater_item) {
$subkey_object = get_sub_field_object($repeater_key);
var_dump($subkey_object['key']);
$field_object['value'][$sub_key][$subkey_object['key']] = $field_object['value'][$sub_key][$repeater_key];
// unset($field_object['value'][$sub_key][$repeater_key]);
}
}
}
}
Result:
array(4) {
[0]=>
array(4) {
["icon"]=>
string(6) "ico-01"
["txt"]=>
string(37) "22"
["field_5c8f423a718f0"]=>
string(6) "ico-01"
["field_5c8f43e5076f7"]=>
string(37) "22"
}
[1]=>
array(4) {
["icon"]=>
string(6) "ico-02"
["txt"]=>
string(42) "22"
["field_5c8f423a718f0"]=>
string(6) "ico-02"
["field_5c8f43e5076f7"]=>
string(42) "22"
}
[2]=>
array(4) {
["icon"]=>
string(6) "ico-03"
["txt"]=>
string(31) "22"
["field_5c8f423a718f0"]=>
string(6) "ico-03"
["field_5c8f43e5076f7"]=>
string(31) "22"
}
[3]=>
array(4) {
["icon"]=>
string(6) "ico-04"
["txt"]=>
string(44) "22"
["field_5c8f423a718f0"]=>
string(6) "ico-04"
["field_5c8f43e5076f7"]=>
string(44) "22"
}
}
But it’s very ugly and won’t run for every field type.
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!
Are you building WordPress sites with ACF and @BeaverBuilder, and wanted to use your ACF Blocks in both the block editor and Beaver Builder?
— Advanced Custom Fields (@wp_acf) May 10, 2023
The BB team recently added support for using ACF Blocks in Beaver Builder. Check it out 👇https://t.co/UalEIa5aQi
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.