ExpressionEngine Docs

Anatomy of a Pro Search Filter

Below is the skeleton of a Pro Search Filter, containing the default properties and methods.

class Pro_search_filter_foo extends Pro_search_filter {

    protected $params;
    protected $fields;
    protected $priority = 5;

    public function filter($entry_ids)
    {
        return $entry_ids;
    }

    public function fixed_order()
    {
        return FALSE;
    }

    public function exclude()
    {
        return NULL;
    }

    public function results($rows)
    {
        return $rows;
    }

}

Properties

$params

(object) — a shortcut to the ee()->pro_search_params object for easy access to the current search parameters. Use $this->params in your methods.

$fields (v4.2.0)

(object) — a shortcut to the ee()->pro_search_fields object for easy access to the Fields library. Use $this->fields in your methods.

$priority

(int) — indicates when this filter should be executed regarding other filters. Filters with priority 1 will be executed before filters with priority 2, and so on. If the priority of your filter is irrelevant, you can omit it from your class. Defaults to 5.

Methods

filter

Use this method to filter channel entries.

Arguments

  • $entry_ids (null or array) — the current search results or NULL if no filter has been triggered yet.

Returns

An array of entry IDs, an empty array (no results), or NULL (if given and your filter is not triggered).

fixed_order

Should return TRUE or FALSE depending on whether the entry IDs returned by the filter method are in the order they should appear in the Results tag. Defaults to FALSE.

Returns

Bool

exclude (v5.2.0)

Should return an array of entry IDs that should be excluded from the search results or NULL if no specific entries should be excluded.

Returns

Array or NULL

results

This method is called before displaying the search results in the Results tag so you can add your own custom variables to the search results. It basically piggy-backs on the channel_entries_query_result extension hook.

Arguments

  • $rows (array) — the entries that are about to be displayed. Note: just like the hook, this does not mean all search results. Just the one on the current page.

Returns

The (modified) array of entries.