add_row()
Adds a new data row to the existing value of a Repeater or Flexible Content field.
No Hooks.
Returns
(boolean). The updated row count, or false on error.
Usage
add_row( $selector, $value, $post_id )
- $selector(string) (required)
- The field name or key.
- $value(array)
- The row containing new data.
Default: false - $post_id(integer/mixed)
- The post ID in which to save the data.
Default: false (the current post)
Examples
#1 Add a new row using field names
This example shows how to add a new data row to an existing image repeater field. This field contains three subfields: image, alt, and link.
$row = [ 'image' => 123, 'alt' => 'Another great sunset', 'link' => 'http://website.com' ]; add_row( 'images', $row );
#2 Add a new row using field keys
This example shows how to add a new data row to an existing Repeater field using keys instead of names. The Repeater field is the same as in the example above.
Like update_field(), using the field key instead of its name allows ACF to find the field correctly when the saved value does not exist.
$row = [ 'field_560389746a525' => 123, 'field_560389746a524' => 'Another great sunset', 'field_560389746a528' => 'http://website.com' ]; add_row( 'field_560389746a51f', $row );
Changelog
| Since 5.2.3 | Introduced. |