Output search filters to be used with find().
public function filters ( $params = null )
Source File: /pods/classes/Pods.php
Since: 2.0
Contents
Parameters
| Parameter | Type | Details |
|---|---|---|
| $params | (string or array) | Comma-separated list of fields or array of parameters. |
Additional Parameter Options
| Option | Type | Default | Details |
|---|---|---|---|
| fields | (string or array) | $params | Comma-separated list or array of field names. Only relationship fields are currently supported. |
| label | (string) | Search | Label of filter submit button. |
| action | (string) | n/a | Action value to use in the <form action="xyz"> |
| search | (string) | $_GET[$this->search_var] | Search string in search field. |
Returns
(string) Filters HTML
Examples
Example 1
<?php
$pod = pods( 'mypod' );
// Output a filter form with just a text box to search.
echo $pod->filters();
// Output a filter form that shows two drop-downs for two relationship fields.
echo $pod->filters( array(
'fields' => array( 'relationship_one', 'relationship_two' )
) );
// The same as above, except the submit button text says 'Go'.
echo $pod->filters( array(
'fields' => array( 'relationship_one', 'relationship_two' ),
'label' => 'Go'
) );
// When you query the items, search is automatically handled (filters must be called before find).
$pod->find();
// Output the list of the items found.
echo '<ul>';
while ( $pod->fetch() ) {
echo "<li>" . $pod->display( 'some_field' ) . '</li>';
}
echo '</ul>';
// Add some pagination if you'd like.
echo $pod->pagination();
Only Show Items After Filtering
Filter books Pod by author. An additional conditional check has been added to prevent any items from showing until after the search is run.
<?php
$pods = pods( 'books');
// Output a filter form that shows one drop-down for the relationship field.
echo $pods->filters( array(
'fields' => array( 'author'),
) );
// Don't display anything until search is submitted.
$search = sanitize_text_field( pods_v( 'search' ) );
if ( 0 < strlen( $search ) ) {
// When you query the items, search is automatically handled (filters must be called before find).
$pods->find();
// Output the list of the items found by using a template (automatically for each).
echo $pods->template( 'books_search');
}