save_pod_item
(Since 1.7.9) -- add or edit a pod item
function save_pod_item($params)
Parameters
The following options are contained within the $params variable as an ARRAY.
| Parameter | Type | Details |
|---|---|---|
| datatype | STRING | Pod Name |
| tbl_row_id | INT | Pod Item ID (optional, if not provided save_pod_item will INSERT instead of UPDATE) - you can get this with $Record->get_field('id') |
| pod_id | INT | DEPRECATED - Pod ID (optional, if not provided save_pod_item will INSERT instead of UPDATE) - you can get this with $Record->get_pod_id() |
| columns | ARRAY | An associative of the column names and values (see examples) |
| data | ARRAY | (optional) Instead of providing a columns array, you can add multiple new items all at once by providing each of their column arrays within this 'data' array |
Security and Data Sanitization
We strongly recommend running all of your data through our pods_sanitize function before saving. Otherwise, your data could cause errors in the saving process and make your code insecure.
$data = pods_sanitize($data);
PICK and FILE column values
These column types should save the related ID. For multiple IDs, separate by comma.
Examples
This code will add a new item to the 'person' Pod.
// gender is a PICK column, the value must be the ID(s) of the related item(s),
// separate multiple by comma (if column has 'multiple' option checked)
// in this case, 1 = Male and 2 = Female
// initialize the api
$api = new PodAPI();
// all of the values to save and options to use
$params = array('datatype' => 'person', 'columns' => array('name' => 'Rick', 'favorite_color' => 'Blue', 'gender' => 1));
// sanitize the data (to keep your code database-safe)
$params = pods_sanitize($params);
// create the item
$person_id = $api->save_pod_item($params);
This code will edit an item in the 'person' Pod.
// initialize the api
$api = new PodAPI();
// all of the values to save and options to use (tbl_row_id based)
$params = array('datatype' => 'person', 'tbl_row_id' => 2, 'columns' => array('name' => 'Rick', 'favorite_color' => 'Blue', 'gender' => 1));
// sanitize the data (to keep your code database-safe)
$params = pods_sanitize($params);
// save the item
$api->save_pod_item($params);
// add new items more than one at a time
$columns = array(
array('name' => 'Rick', 'favorite_color' => 'Blue', 'gender' => 1),
array('name' => 'James', 'favorite_color' => 'Red', 'gender' => 1),
array('name' => 'Katy', 'favorite_color' => 'Green', 'gender' => 2)
);
$params = array('datatype' => 'person', 'data' => $columns);
// sanitize the data (to keep your code database-safe)
$params = pods_sanitize($params);
// save the item
$api->save_pod_item($params);
