Created
March 10, 2015 09:19
-
-
Save jonathan-dejong/887e72a19397fa133b6a to your computer and use it in GitHub Desktop.
Modify update_sub_field to allow for inserting numbered rows even when no rows exist yet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Change this | |
* =============================== | |
*/ | |
// sub fields | |
foreach( $selector as $s ) { | |
if( is_numeric($s) ) { | |
$row_i = intval($s) - 1; | |
// add to name | |
$name .= "_{$row_i}"; | |
} else { | |
// update parent | |
$field = acf_get_sub_field( $s, $field ); | |
// create dummy field | |
if( !$field ) { | |
$field = acf_get_valid_field(array( | |
'name' => $s, | |
'key' => '', | |
'type' => '', | |
)); | |
} | |
// add to name | |
$name .= "_{$field['name']}"; | |
} | |
// if | |
} | |
/* To this | |
* =============================== | |
*/ | |
// sub fields | |
foreach( $selector as $s ) { | |
if( is_numeric($s) ) { | |
$row_i = intval($s) - 1; | |
// update parent | |
$field = acf_get_sub_field( $s, $field ); | |
// create dummy field | |
if( !$field ) { | |
$field = acf_get_valid_field(array( | |
'name' => $s, | |
'key' => '', | |
'type' => '', | |
)); | |
// add to name | |
$name .= "_{$field['name']}"; | |
}else{ | |
// add to name | |
$name .= "_{$row_i}"; | |
} | |
} else { | |
// update parent | |
$field = acf_get_sub_field( $s, $field ); | |
// create dummy field | |
if( !$field ) { | |
$field = acf_get_valid_field(array( | |
'name' => $s, | |
'key' => '', | |
'type' => '', | |
)); | |
} | |
// add to name | |
$name .= "_{$field['name']}"; | |
} | |
// if | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment