get_field
get a column value
This function returns a column value.
function get_field($name, $orderby = null)
Parameters
ParameterTypeDetails
$name
STRING
the column name
$orderby
STRING
(optional) if a PICK column, how to sort the results (e.g. “name ASC”)
Returns
- PICK column: ARRAY
- PICK column single field (e.g. “person.name” or “person.mother.name”): STRING
- File column: ARRAY
- File column single field (e.g. “file.guid”): STRING
- Other column types: STRING
- Returns false on error.
Examples
Using get_field() in List Pages:
<?php
$pods = new Pod('pod_name');
$pods->findRecords('id DESC', 15);
while ($pods->fetchRecord())
{
echo $pods->get_field('column_name');
echo $pods->get_field('pick_or_file_upload_name.column_name');
}
?>
Using get_field() in Detail Pages:
<?php
$item_id = 1; // You must find this ID manually!
$pods = new Pod('pod_name', $item_id);
echo $pods->get_field('column_name');
?>
Using get_field() in Pod Templates and Helpers:
<?php
echo $this->get_field('column_name');
?>
Here's a trick to get your relationship data always returning the way you want it:
<?php
// get an array of the values, even if there's only one
$data = (array) $pod->get_field('related.other.field');
// get an array of the value field arrays, even if there's only one field array
$data = (array) $pod->get_field('related.other');
if ( isset( $data[ 'name' ] ) {
$data = array( $data );
}