filters()

Output search filters to be used with find().

Output search filters to be used with find().

public function filters ( $params = null )

Source File: /pods/classes/Pods.php

Since: 2.0

Parameters

ParameterTypeDetails
$params(string or array)Comma-separated list of fields or array of parameters.

Additional Parameter Options

OptionTypeDefaultDetails
fields(string or array)$paramsComma-separated list or array of field names. Only relationship fields are currently supported.
label(string)SearchLabel of filter submit button.
action(string)n/aAction 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');
}

Other Helpful Documentation on pods()

add_to()

Add an item to the values of a relationship field.

add()

Add an item to a Pod.

data()

Return an array of all rows returned from a find() call.

delete()

Delete an item from the Pod.

display()

Return the output for a field.

do_magic_tags()

Replace magic tags with their values.

duplicate()

Duplicate an item.

exists()

Whether a Pod item exists or not when using fetch() or construct with an ID or slug.

export_data()

Export data from all items.

export()

Export an item’s data.

fetch()

Fetch an item from a Pod.

field()

Return the value for a field.

fields()

Return field array from a Pod, a field’s data, or a field option.

find()

Find items of a pod.

first_id()

Return the first item ID.

form()

Embed a form to add / edit a pod item from within your theme.

helper()

Run a helper within a Pod Page or WP Template.

id()

Return the item ID.

import()

Import data.

index()

Return the item name.

last_id()

Return the last item ID.

next_id()

Return the next item ID.

nth()

Fetch the nth state.

pagination()

Display the pagination controls.

position()

Fetch the current position in the loop.

prev_id()

Return the previous item ID.

raw()

Return the raw output for a field.

remove_from()

Remove values from fields.

reset_pod()

Delete all items from the Pod.

reset()

Reset the item position back to the start of the find() list.

row()

Return row array for an item.

save()

Save an item.

template()

Display the page template.

total_found()

Fetch to total number of rows found.

total()

Fetch the total row count.

valid()

Pod object validity.

zebra()

Fetch the zebra switch.