save()

Save an item.

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.

Function Definition

public function save ( $data = null, $value = null, $id = null )

Source File: /pods/classes/Pods.php

Since: 2.0

Parameters

PARAMETERTYPEDETAILS
$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

Returns

(int) The item ID.

Examples

Save Multiple Fields At Once

<?php
// 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 );

Other Helpful Documentation on pods()

add_to()

Add an item to the values of a relationship field.

add()

Add an item to a Pod.

data()

Return an array of all rows returned from a find() call.

delete()

Delete an item from the Pod.

display()

Return the output for a field.

do_magic_tags()

Replace magic tags with their values.

duplicate()

Duplicate an item.

exists()

Whether a Pod item exists or not when using fetch() or construct with an ID or slug.

export_data()

Export data from all items.

export()

Export an item’s data.

fetch()

Fetch an item from a Pod.

field()

Return the value for a field.

fields()

Return field array from a Pod, a field’s data, or a field option.

filters()

Output search filters to be used with find().

find()

Find items of a pod.

first_id()

Return the first item ID.

form()

Embed a form to add / edit a pod item from within your theme.

helper()

Run a helper within a Pod Page or WP Template.

id()

Return the item ID.

import()

Import data.

index()

Return the item name.

last_id()

Return the last item ID.

next_id()

Return the next item ID.

nth()

Fetch the nth state.

pagination()

Display the pagination controls.

position()

Fetch the current position in the loop.

prev_id()

Return the previous item ID.

raw()

Return the raw output for a field.

remove_from()

Remove values from fields.

reset_pod()

Delete all items from the Pod.

reset()

Reset the item position back to the start of the find() list.

row()

Return row array for an item.

template()

Display the page template.

total_found()

Fetch to total number of rows found.

total()

Fetch the total row count.

valid()

Pod object validity.

zebra()

Fetch the zebra switch.