forked from pods-framework/pods
-
Notifications
You must be signed in to change notification settings - Fork 0
Fetch()
bonsak edited this page Nov 20, 2012
·
3 revisions
Fetch an item from a Pod. If $id is null, it will return the next item in the list after running find(). You can rewind the list back to the start by using reset().
Providing an $id will fetch a specific item from a Pod, much like a call to pods() will do, and can handle either an id or slug.
public function fetch (
$id = null
)
Parameter | Type | Details |
---|---|---|
$id | int | (optional) ID or slug of the item to fetch |
(array) An array of fields from the row
<?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->display( 'name' ); ?></h2>
<p>Author: <?php echo $books->display( 'the_author' ); ?></p>
<br />
<p>Category: <?php echo $books->display( 'category' ); ?></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 />
2.0+