forked from pods-framework/pods
-
Notifications
You must be signed in to change notification settings - Fork 0
field()
pglewis edited this page Dec 15, 2012
·
1 revision
Return the value for a field. If you are getting a field for output in a theme, most of the time you will want to use display() instead. This function will return arrays for relationship and file fields.
public function field (
$name,
$single = false
)
Parameter | Type | Details |
---|---|---|
$name | string or array | The field name, or an associative array of parameters |
$single | boolean | (optional) For tableless fields, to return the whole array or the just the first item |
Option | Type | Default | Details |
---|---|---|---|
name | string | $name | The field name |
orderby | string | null | (optional) For tableless fields, you can choose to return an array of items in a specific order |
single | bool | $single | (optional) For tableless fields, to return the whole array or the just the first item |
in_form | bool | false | (optional) For internal use. If set to true, always return a full array of data |
(mixed) or (null) Value returned depends on the field type, null if the field doesn't exist, false if no value returned for tabl
<?php
// We have a "books" Pod with "category" and "the_author"
// as single-select relationship fields, related to
// "categories" and "authors" Pods
$params = array(
'where' => 't.name LIKE "%rings%"',
'limit' => -1 // Return all rows
);
// Create and find in one shot
$books = pods( 'books', $params );
if ( 0 < $books->total() ) {
while ( $books->fetch() ) {
?>
<h2><?php echo $books->field( 'name' ); ?></h2>
<p>Author: <?php echo $books->field( 'the_author.name' ); ?></p>
<br />
<p>Category: <?php echo $books->field( 'category.name' ); ?></p>
<br />
<?php
} // end of books loop
} // end of found books
<h2>The Lord of the Rings</h2>
<p>Author: J. R. R. Tolkien</p>
<br />
<p>Category: Fiction</p>
<br />
Displaying Pods Items using Pods Pages & Pods Templates Contributed by Masino Sinaga How to use Pods Pages and Pods Templates with magic tags to show pods data.
2.0+
field() is located in /pods/classes/Pods.php