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

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

We covered this method extensively in the PodsCast episode #1

 

Source File: /pods/classes/Pods.php

Parameters

PARAMETER TYPE DETAILS
$params (array|string|int) An associative array of parameters, or the ID of the item, or for advanced content types the item’s slug.
$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, ie “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
groupby (string) null SQL GROUP BY, like ‘t.city’.
limit (int) $limit Limit the number of items to find, use -1 to return all items with no limit
offset (int) null Override what’s calculated automatically based on ‘limit’ and ‘page’
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

(Pods) The pod object

Examples

Example 1

The above example will output:

Using a variable in a where clause

When the where clause must be created dynamically, a variable can be passed to it like in this example:

See Also

Find Reference Table

Reference table for use in where clauses in Find and Pods Shortcodes.

Skip to toolbar