Taxonomy extends Filter implements Indexable_Interface, Storable_Interface, Filterable_Interface, Countable_Interface, Preloadable_Interface Uses Prefilling_Aware, Search_Query_Array_Aware, Taxonomy_Counts_Provider, Specific_Terms_Aware
Responsible for generating taxonomy related data inside the indexer.
Interfaces, Classes and Traits
- Indexable_Interface
- Indexable_Interface provides a single method "generate_index_data".
- Storable_Interface
- Represents a filter that should attach data to the frontend react data store.
- Filterable_Interface
- Indicates that a filter is capable of filtering the WP query.
- Countable_Interface
- Indicates that the filter can provide a list of counts of the available choices.
- Preloadable_Interface
- Indicates that a filter should preload counts of possible choices on page load.
Table of Contents
- $fillable : array<string|int, mixed>
- $timestamps : bool
- $appends : array<string|int, mixed>
- $casts : array<string|int, mixed>
- Automatically cast attributes in specific ways.\
- $childColumn : string
- Indicates the column that should be used by the HasChildren trait to return the appropriate model.
- $childTypes : array<string|int, mixed>
- Maps a filter_by value to the appropriate model.
- $primaryKey : string
- $table : string
- $with_hierarchy : array<string|int, mixed>
- List of inputs that should support hierarchy indentation.
- __construct() : void
- Create a new instance of the model.
- create() : self
- Create the filter.
- delete() : bool
- Delete the filter from the database.
- find_posts() : mixed
- generate_index_data() : array<string|int, mixed>
- Generate data for the indexer.
- get_all_choices_counts() : mixed
- get_attribute_orderby_args() : mixed
- get_choices_counts() : mixed
- get_groups() : Collection
- Get a list of the groups to which the filter belongs to.
- get_json_store_data() : mixed
- Get the json data to attach to the frontend react data store.
- get_option() : mixed
- Get the value of a specific option if it exists.
- get_options() : array<string|int, mixed>
- Get the filter's options.
- get_search_query() : mixed
- get_specific_terms() : array<string|int, mixed>
- Get the specific terms for the taxonomy filter.
- get_taxonomy_slug() : string|false
- Get the proper taxonomy slug based on the type of source selected.
- getFilterByAttribute() : string
- Adds backwards compatibility for the old filter_by option.
- getGroupsAttribute() : array<string|int, mixed>
- Lazy load the list of groups to which the filter has been added to.
- getGroupsNamesAttribute() : array<string|int, mixed>
- Lazy load the list of groups to which the filter has been added to.
- getHiddenAttribute() : bool
- Determine if this filter is hidden in the admin panel.
- getInputNameAttribute() : string
- Retrieve the human readable name of the selected input type for the filter.
- getSearchQueryAttribute() : mixed
- Get the search query parameters assigned to the filter.
- getSourceNameAttribute() : string
- Retrieve the human readable name of the selected source for the filter.
- include_variations() : mixed
- incrementSlug() : string
- Increment slug
- is_hierarchical() : bool
- Determines if the filter is a dropdown and if hierarchical mode is enabled.
- maybe_regenerate_child_filters() : void
- Regenerate the child filters for attributes filters.
- setSearchQueryAttribute() : Filter
- Attach search parameters criteria to the filter.
- setSlugAttribute() : void
- Automatically set the slug attribute by counting for existing ones.
- supports_hierarchy() : bool
- Determine if the filter supports hierarchy given it's type.
- update_groups() : Filter
- Add the filter to the new groups and remove the filter from all other groups.
- getChildModel() : mixed
- should_restrict() : bool
- Checks if results should be restricted or merged.
- taxonomy_filter_should_restrict() : bool
- Determine if filtering should be restricted to match all filters when one or more filter is enabled and is a checkbox.
Properties
$fillable
public
array<string|int, mixed>
$fillable
= ['name', 'slug', 'filter_by', 'priority', 'options', 'parent_filter']
$timestamps
public
bool
$timestamps
= \false
$appends
protected
array<string|int, mixed>
$appends
= ['source_name', 'input_name', 'search_query', 'hidden']
$casts
Automatically cast attributes in specific ways.\
protected
array<string|int, mixed>
$casts
= ['options' => 'array']
$childColumn
Indicates the column that should be used by the HasChildren trait to return the appropriate model.
protected
string
$childColumn
= 'filter_by'
$childTypes
Maps a filter_by value to the appropriate model.
protected
array<string|int, mixed>
$childTypes
= ['categories' => \Barn2\Plugin\WC_Filters\Model\Filters\Taxonomy::class, 'tags' => \Barn2\Plugin\WC_Filters\Model\Filters\Taxonomy::class, 'attributes' => \Barn2\Plugin\WC_Filters\Model\Filters\Attribute::class, 'colors' => \Barn2\Plugin\WC_Filters\Model\Filters\Color::class, 'price' => \Barn2\Plugin\WC_Filters\Model\Filters\Price::class, 'ratings' => \Barn2\Plugin\WC_Filters\Model\Filters\Rating::class, 'in_stock' => \Barn2\Plugin\WC_Filters\Model\Filters\Stock::class, 'on_sale' => \Barn2\Plugin\WC_Filters\Model\Filters\Sale::class, 'taxonomy' => \Barn2\Plugin\WC_Filters\Model\Filters\Taxonomy::class, 'sorter' => \Barn2\Plugin\WC_Filters\Model\Filters\Sorter::class, 'cf' => \Barn2\Plugin\WC_Filters\Model\Filters\Custom_Field::class, 'search' => \Barn2\Plugin\WC_Filters\Model\Filters\Search::class]
$primaryKey
protected
string
$primaryKey
= 'id'
$table
protected
string
$table
= \Barn2\Plugin\WC_Filters\Plugin::META_PREFIX . 'filters'
$with_hierarchy
List of inputs that should support hierarchy indentation.
protected
array<string|int, mixed>
$with_hierarchy
= ['dropdown', 'checkboxes', 'radio']
Methods
__construct()
Create a new instance of the model.
public
__construct([array<string|int, mixed> $attributes = [] ]) : void
Parameters
- $attributes : array<string|int, mixed> = []
Return values
void —create()
Create the filter.
public
static create([array<string|int, mixed> $attributes = [] ][, array<string|int, mixed> $groups = [] ]) : self
If this is an "all attributes" type of filter, create the child filters too.
The $groups parameter is only used for attribute fields when generating child filters.
Parameters
- $attributes : array<string|int, mixed> = []
- $groups : array<string|int, mixed> = []
-
list of groups to which the filter should be added to.
Return values
self —delete()
Delete the filter from the database.
public
delete() : bool
This has a cascading effect:
- deletes all data indexed for this filter
- removes the filter from all groups to which it was added.
Return values
bool —find_posts()
public
find_posts() : mixed
Tags
Return values
mixed —generate_index_data()
Generate data for the indexer.
public
generate_index_data(array<string|int, mixed> $defaults, string $post_id) : array<string|int, mixed>
Parameters
- $defaults : array<string|int, mixed>
-
default index values
- $post_id : string
-
the ID of the post to index
Tags
Return values
array<string|int, mixed> —get_all_choices_counts()
public
get_all_choices_counts([array<string|int, mixed> $post_ids = [] ]) : mixed
Parameters
- $post_ids : array<string|int, mixed> = []
Tags
Return values
mixed —get_attribute_orderby_args()
public
get_attribute_orderby_args(mixed $taxonomy) : mixed
Parameters
- $taxonomy : mixed
Return values
mixed —get_choices_counts()
public
get_choices_counts(array<string|int, mixed> $post_ids[, mixed $filters = false ][, mixed $prefilling = false ]) : mixed
Parameters
- $post_ids : array<string|int, mixed>
- $filters : mixed = false
- $prefilling : mixed = false
Tags
Return values
mixed —get_groups()
Get a list of the groups to which the filter belongs to.
public
get_groups() : Collection
This method is required because when using Eloquent in WordPress, we cannot reliably build a json relationship.
Return values
Collection —get_json_store_data()
Get the json data to attach to the frontend react data store.
public
get_json_store_data() : mixed
Tags
Return values
mixed —get_option()
Get the value of a specific option if it exists.
public
get_option(string $key) : mixed
If not, it returns false.
Parameters
- $key : string
Return values
mixed —false when not found
get_options()
Get the filter's options.
public
get_options() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_search_query()
public
get_search_query() : mixed
Tags
Return values
mixed —get_specific_terms()
Get the specific terms for the taxonomy filter.
public
get_specific_terms() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_taxonomy_slug()
Get the proper taxonomy slug based on the type of source selected.
public
get_taxonomy_slug() : string|false
Return values
string|false —getFilterByAttribute()
Adds backwards compatibility for the old filter_by option.
public
getFilterByAttribute(string $value) : string
This option was used to determine if the filter should be based on a taxonomy.
If the attribute is set to taxonomy, then the taxonomy option will be used instead.
Parameters
- $value : string
-
The value of the option.
Return values
string —getGroupsAttribute()
Lazy load the list of groups to which the filter has been added to.
public
getGroupsAttribute() : array<string|int, mixed>
Return values
array<string|int, mixed> —getGroupsNamesAttribute()
Lazy load the list of groups to which the filter has been added to.
public
getGroupsNamesAttribute() : array<string|int, mixed>
Return an array of ID=>name.
Return values
array<string|int, mixed> —getHiddenAttribute()
Determine if this filter is hidden in the admin panel.
public
getHiddenAttribute() : bool
Hidden filters are generated when an "all attributes" type of filter is created.
Return values
bool —getInputNameAttribute()
Retrieve the human readable name of the selected input type for the filter.
public
getInputNameAttribute() : string
Return values
string —getSearchQueryAttribute()
Get the search query parameters assigned to the filter.
public
getSearchQueryAttribute() : mixed
Return values
mixed —getSourceNameAttribute()
Retrieve the human readable name of the selected source for the filter.
public
getSourceNameAttribute() : string
Return values
string —include_variations()
public
include_variations() : mixed
Return values
mixed —incrementSlug()
Increment slug
public
incrementSlug(string $slug) : string
Parameters
- $slug : string
Return values
string —is_hierarchical()
Determines if the filter is a dropdown and if hierarchical mode is enabled.
public
is_hierarchical() : bool
Return values
bool —maybe_regenerate_child_filters()
Regenerate the child filters for attributes filters.
public
static maybe_regenerate_child_filters(Filter $filter) : void
Parameters
- $filter : Filter
-
the filter to regenerate.
Return values
void —setSearchQueryAttribute()
Attach search parameters criteria to the filter.
public
setSearchQueryAttribute(mixed $value) : Filter
These are the instructions that will be used via the Filterable_Interface method.
Parameters
- $value : mixed
Return values
Filter —setSlugAttribute()
Automatically set the slug attribute by counting for existing ones.
public
setSlugAttribute(string $value) : void
Parameters
- $value : string
Return values
void —supports_hierarchy()
Determine if the filter supports hierarchy given it's type.
public
supports_hierarchy() : bool
Return values
bool —update_groups()
Add the filter to the new groups and remove the filter from all other groups.
public
update_groups(array<string|int, mixed> $selected_groups) : Filter
This method is best used when pre-serving the position of the filter into a group is needed.
Parameters
- $selected_groups : array<string|int, mixed>
-
list of IDs of groups to which the filter should be added to.
Return values
Filter —getChildModel()
protected
getChildModel(array<string|int, mixed> $attributes) : mixed
Parameters
- $attributes : array<string|int, mixed>
Return values
mixed —should_restrict()
Checks if results should be restricted or merged.
private
should_restrict(bool $prefilling[, array<string|int, mixed> $other_filters = [] ]) : bool
Parameters
- $prefilling : bool
- $other_filters : array<string|int, mixed> = []
Return values
bool —taxonomy_filter_should_restrict()
Determine if filtering should be restricted to match all filters when one or more filter is enabled and is a checkbox.
private
taxonomy_filter_should_restrict(mixed $prefilling[, array<string|int, mixed> $other_filters = [] ]) : bool
Parameters
- $prefilling : mixed
- $other_filters : array<string|int, mixed> = []