Skip to content
gingerbeardman edited this page Apr 6, 2013 · 4 revisions

find()

Find items of a pod, much like WP_Query, but with advanced table handling.

public function find ( 
	$params = null, 
	$limit = 15, 
	$where = null, 
	$sql = null 
)

Parameters

Parameter Type Details
$params array An associative array of parameters
$limit int (optional) (deprecated) Limit the number of items to find, use -1 to return all items with no limit
$where string (optional) (deprecated) SQL WHERE declaration to use
$sql string (optional) (deprecated) For advanced use, a custom SQL query to run

Additional Parameter Options

Option Type Default Details
where string $where SQL WHERE to use, like "t.my_field = 'test'" - This field also supports tableless traversal like "my_relationship_field.id = 3" with unlimited depth
orderby string null SQL ORDER BY to use, like "t.name DESC" - This field also supports tableless traversal like "my_relationship_field.name DESC" with unlimited depth
limit int $limit Limit the number of items to find, use -1 to return all items with no limit
search bool true Whether to handle search. Defaults to $this->search, which can be globally overridden by defining the constant PODS_GLOBAL_POD_SEARCH to true/false
pagination bool true Whether to handle pagination. Defaults to $this->pagination, which can be globally overridden by defining the constant PODS_GLOBAL_POD_PAGINATION to true/false
page int 1 Specify a page of the results to get. Defaults to $this->page,
table string Default of current pod type Table to base find() off of
select string t.* or t., d. Fields to select from the database. The "t" prefix will reference the primary table, "d" prefixes are used for the Pod table for any WP Object and the "t" prefix references that WP Object (wp_posts, wp_terms, wp_users, wp_comments)
join string or array null Additional table(s) to JOIN, using SQL syntax like "LEFT JOIN my_table ON my_table.id = t.id"
expires int null Whether to cache the results or not, 0 will cache it until caches are cleared, 1+ will cache it for X amount of seconds; Default is no caching (null)
cache_mode string cache Cache mode to use, available options are cache, transient, or site-transient

Returns

The Pod object

Example

<?php
// Find can be called in one of three ways

// Example #1
$mypod = pods( 'mypod', $params );

// Example #2
$mypod = pods( 'mypod' )->find( $params );

// Example #3
$mypod = pods( 'mypod' );
$mypod->find( $params );


// Here's how to use find()
$params = array(
    'limit' => 3, 
    'page' => 2, 
    // Be sure to sanitize ANY strings going here
    'where'=>"category.name = 'My Category'"
);

// Run the find
$mypod = pods( 'mypod', $params );

// Loop through the records returned
while ( $mypod->fetch() ) {
    echo $mypod->display( 'name' ) . "\n";
}
The above example will output:
Pod Title 1
Pod Title 2
Pod Title 3

Tutorials and other Resources

Building a Store Locator with proximity search using Pods Contributed by jchristopher Learn how to build a store locator with proximity search

Available Since Version

2.0+

Source File

find() is located in /pods/classes/Pods.php

See Also