Save an item by giving an array of field data or set a specific field to a specific value. Though this function has the capacity to add new items, best practice should direct you to use add() for that instead.
public function save ( $data = null, $value = null, $id = null )
Source File: /pods/classes/Pods.php
|$data||(array|string)||Either an associative array of field information or a field name|
|$value||(mixed)||(optional) Value of the field, if $data is a field name|
|$id||(int)||(optional) ID of the pod item to update|
(int) The item ID
Save Multiple Fields At Once
// Get the book item with an ID of 5
$pod = pods( 'book', 5 );
// Set the author (a user relationship field)
// to a user with an ID of 2
$pod->save( 'author', 2 );
// Set a group of fields to specific values
$data = array(
'name' => 'New book name',
'author' => 2,
'description' => 'Awesome book, read worthy!'
// Save the data as set above
$pod->save( $data );
// Let's save another book's data..
// Save the same data from above,
// but for the book with an ID of 4
$pod->save( $data, null, 4 );
Add An Image Submitted In A Form
You can add an image to a image field using pods::save() by passing the file path or the URL for the image.
IMPORTANT: This example skips data sanitization and validation for the sake of simplicity to explain a concept. Do not use as is, always sanitize data from a form.
//get URL of image from form input
$img = $_POST[ 'image' ];
//add image to media library and get its ID
$img = pods_attachment_import( $img );
//create array of data to be added
//You can add additional fields here if you want
$data = array(
'image_field' => $img ,
//get pods object for item of ID $id
$pod = pods( 'pod_name', $id );
//update the item and return item id in $item
$item = $pod->save( $data);