The PHP API
Writing and deleting
ugly_update( 'price', 120 ); // on the current post
ugly_update( 'price', 120, 42 ); // on post 42
ugly_update( 'team', array( // a whole repeater
array( 'name' => 'Ana', 'role' => 'Chef' ),
array( 'name' => 'Luis', 'role' => 'Baker' ),
), 42 );
ugly_delete( 'price', 42 );What you write goes through the same cleaning as what the editor writes. A number out of range is cut. A badly typed color is dropped. A value that does not belong is not saved.
Both return true when something was written (or deleted) and false when it was not.
A common recipe: add one row to a repeater
Rows come out as objects, so convert each one to an array, add yours, and write the list back:
$rows = array_map(
static fn ( $row ) => $row->toArray(),
ugly_rows( 'team', 42 )
);
$rows[] = array( 'name' => 'Marta', 'role' => 'Waiter' );
ugly_update( 'team', $rows, 42 );Did this article answer your question?
Thank you. It helps us make the documentation better. Need more help?