Blog

Differences between 1.x and 2.0

We’re going to use this post to keep track of the deprecated functions and methods for you to reference at a glance. Pods 2.0 is backwards compatible, but we recommend you update your usage as you’re able to so you avoid any headaches down the road.

Pod() class

The Pod() class has had a makeover! Below are some new things you can do, we hope you enjoy the changes.

Calling the Pod() class

The Pod() class has been renamed to Pods(), your old code should point at the new class and methods though, but you should take advantage of the new usage which is much easier to use and understand.

Old

// Get data for a pod
$mypod = new Pod( 'mypod' );

// Get data for an item
$mypod = new Pod( 'mypod', $id_or_slug );

// Maps to findRecords
$mypod = new Pod( 'mypod', $params );

New

// Get the pod object
$mypod = pods( 'mypod' );

// Get data for an item
$mypod = pods( 'mypod', $id_or_slug' );

// Maps to the new find method
$mypod = pods( 'mypod', $params );

// NEW! Get the pod object, find data, output each item using the template
echo pods( 'mypod' )->find( $params )->template( 'template/name' );

get_field

Old

// Get a field's value
$value = $mypod->get_field( 'my_field' );

// Get the value of 'name' from the related field's item(s)
$name = $mypod->get_field( 'my_related_field.name' );

// Order the return of the related field values
$value = $mypod->get_field( 'my_related_field', 'name DESC' );

New

// Get a field's value
$value = $mypod->field( 'my_field' );

// Get the value of 'name' from the related field's item(s)
$name = $mypod->field( 'my_related_field.name' );

// Order the return of the related field values
$params = array( 'name' => 'my_related_field', 'orderby' => 'name DESC' );
$value = $mypod->field( $params );

// NEW: Get the first value of the related items, just like get_post_meta( $id, $key, $single ) works
$params = array( 'name' => 'my_related_field', 'single' => true );
$value = $mypod->field( $params );

// NEW: Get the first value of the related items, just like get_post_meta( $id, $key, $single ) works
$value = $mypod->field( 'my_related_field', true );

findRecords

Old

// Get 15 records, ordered by name descending, where the name isn't Buster
$mypod->findRecords( 'name DESC', 15, 'name != "Buster"' );

// Get 15 records, ordered by name descending, where the name isn't Buster
$params = array( 'orderby' => 'name DESC', 'limit' => 15, 'where' => 'name != "Buster"' );
$mypod->findRecords( $params );

// Get 15 records, ordered by name descending, where the name isn't Buster
$params = array( 'orderby' => 'name DESC', 'limit' => 15, 'where' => 'name != "Buster"' );
$mypod = new Pod( 'mypod', $params );

New

// Get 15 records, ordered by name descending, where the name isn't Buster
$params = array( 'orderby' => 'name DESC', 'limit' => 15, 'where' => 'name != "Buster"' );
$mypod->find( $params );

// Get 15 records, ordered by name descending, where the name isn't Buster
$params = array( 'orderby' => 'name DESC', 'limit' => 15, 'where' => 'name != "Buster"' );
$mypod = pods( 'mypod', $params );

// Get 15 records, ordered by name descending, where the name isn't Buster
$params = array( 'orderby' => 'name DESC', 'limit' => 15, 'where' => 'name != "Buster"' );
$mypod = pods( 'mypod' )->find( $params );

NEW: Call API methods right from the Pods object!

// Add an item
// It maps to PodsAPI::save_pod_item, does not pass the current ID
$mypod->add( $params );

// Save an item
// It maps to PodsAPI::save_pod_item, automatically passes the current ID for you
$mypod->save( $params );

// Delete an item
// It maps to PodsAPI::delete_pod_item, automatically passes the current ID for you, or you can set another $id to be deleted
$mypod->delete( $id );

// Duplicate an item
// It maps to PodsAPI::duplicate_pod_item, automatically passes the current ID for you, or you can set another $id to be deleted
$mypod->duplicate( $id );