Filters
Helper class for dealing with filters.
Tags
Table of Contents
- calculate_max_price() : float
- Calculate the highest facet_value for a filter.
- create_or_update_filter() : Filter
- Helper function to create or update a filter in the database. This function is used by the admin settings page to save filters.
- custom_field_exists() : bool
- Determine if a custom field exists.
- generate_child_filters() : void
- Generate child filters for an attribute type of filter.
- get_filter_by_id() : Filter|null
- Get a filter by ID.
- get_filters_by_parent_id() : array<string|int, mixed>
- Get filters by parent ID.
- has_unique_sources() : bool|WP_Error
- Determine if filters have unique sources.
- is_reserved_slug() : bool
- Determine if the given slug is reserved by WordPress.
- is_taxonomy_page() : bool
- Determine if we're on a product taxonomy page.
- maybe_adjust_filter_by() : array<string|int, mixed>
- Helper function to adjust the filter by setting.
- maybe_adjust_filter_options() : array<string|int, mixed>
- Helper function to attach taxonomy setting to filter options.
Methods
calculate_max_price()
Calculate the highest facet_value for a filter.
public
static calculate_max_price(Filter $filter) : float
Parameters
- $filter : Filter
-
The filter.
Return values
float —The highest facet_value.
create_or_update_filter()
Helper function to create or update a filter in the database. This function is used by the admin settings page to save filters.
public
static create_or_update_filter(array<string|int, mixed> $filter, int $group_id, int $priority) : Filter
Parameters
- $filter : array<string|int, mixed>
-
The filter data
- $group_id : int
-
The group ID
- $priority : int
-
The filter priority
Return values
Filter —The filter object
custom_field_exists()
Determine if a custom field exists.
public
static custom_field_exists(string $meta_key) : bool
Parameters
- $meta_key : string
-
The meta key.
Return values
bool —generate_child_filters()
Generate child filters for an attribute type of filter.
public
static generate_child_filters(Filter $filter, array<string|int, mixed> $groups) : void
Parameters
- $filter : Filter
-
The filter for which to generate child filters.
- $groups : array<string|int, mixed>
-
The groups to which the child filters should be added to.
Return values
void —get_filter_by_id()
Get a filter by ID.
public
static get_filter_by_id(int $filter_id) : Filter|null
Parameters
- $filter_id : int
-
The filter ID.
Return values
Filter|null —The filter object.
get_filters_by_parent_id()
Get filters by parent ID.
public
static get_filters_by_parent_id(int $parent_id) : array<string|int, mixed>
Parameters
- $parent_id : int
-
The parent ID.
Return values
array<string|int, mixed> —The filters.
has_unique_sources()
Determine if filters have unique sources.
public
static has_unique_sources(array<string|int, mixed> $ids) : bool|WP_Error
Parameters
- $ids : array<string|int, mixed>
-
The filter IDs.
Return values
bool|WP_Error —true if the filters have unique sources, a WP_Error object otherwise.
is_reserved_slug()
Determine if the given slug is reserved by WordPress.
public
static is_reserved_slug(string $slug) : bool
Parameters
- $slug : string
-
the slug to check.
Return values
bool —true if the slug is reserved, false otherwise.
is_taxonomy_page()
Determine if we're on a product taxonomy page.
public
static is_taxonomy_page() : bool
Return values
bool —maybe_adjust_filter_by()
Helper function to adjust the filter by setting.
public
static maybe_adjust_filter_by(array<string|int, mixed> $options, string $filter_by) : array<string|int, mixed>
The value is orginally read from the "filter_method" setting in the filter options.
Parameters
- $options : array<string|int, mixed>
-
The filter options.
- $filter_by : string
-
The filter by setting.
Return values
array<string|int, mixed> —The adjusted filter options.
maybe_adjust_filter_options()
Helper function to attach taxonomy setting to filter options.
public
static maybe_adjust_filter_options(array<string|int, mixed> $options) : array<string|int, mixed>
Other operations may be performed on the options array.
Parameters
- $options : array<string|int, mixed>
-
The filter options.
Return values
array<string|int, mixed> —The adjusted filter options.