Taxonomy_Menu_Order implements Standard_Service, Registerable
Service for ordering taxonomy and attribute filter choices by WordPress menu order.
This service hooks into the wcf_query_possible_choices filter to reorder taxonomy and attribute filter results based on the menu_order defined in the WordPress admin panel. It supports both Taxonomy and Attribute filter types.
Tags
Interfaces, Classes and Traits
- Standard_Service
- Registerable
Table of Contents
- register() : void
- Register the service.
- reorder_taxonomy_choices() : array<string|int, mixed>
- Reorder taxonomy and attribute filter choices by WordPress menu order
- add_terms_hierarchically() : void
- Recursively add terms maintaining hierarchical order.
- build_hierarchical_term_order() : array<string|int, mixed>
- Build hierarchical term order respecting parent-child relationships This ensures that child terms appear after their parents in the correct order.
- get_filter_taxonomy_slug() : string|null
- Get the taxonomy slug for a filter (works for both Taxonomy and Attribute types).
- is_taxonomy_based_filter() : bool
- Check if a filter is taxonomy-based (Taxonomy or Attribute type).
Methods
register()
Register the service.
public
register() : void
Return values
void —reorder_taxonomy_choices()
Reorder taxonomy and attribute filter choices by WordPress menu order
public
reorder_taxonomy_choices(array<string|int, mixed> $results, Query $query) : array<string|int, mixed>
Parameters
- $results : array<string|int, mixed>
-
Array of possible filter choices from the database query
- $query : Query
-
The current Query instance
Return values
array<string|int, mixed> —Filtered array of possible choices
add_terms_hierarchically()
Recursively add terms maintaining hierarchical order.
private
add_terms_hierarchically(int $parent_id, array<string|int, mixed> &$ordered_ids, array<string|int, mixed> $term_children, array<string|int, mixed> $term_objects) : void
Parameters
- $parent_id : int
-
Parent term ID
- $ordered_ids : array<string|int, mixed>
-
Reference to the ordered IDs array
- $term_children : array<string|int, mixed>
-
Children mapping array
- $term_objects : array<string|int, mixed>
-
Term objects array
Return values
void —build_hierarchical_term_order()
Build hierarchical term order respecting parent-child relationships This ensures that child terms appear after their parents in the correct order.
private
build_hierarchical_term_order(array<string|int, mixed> $terms) : array<string|int, mixed>
Parameters
- $terms : array<string|int, mixed>
-
Array of term objects from get_terms()
Return values
array<string|int, mixed> —Array of term IDs in hierarchical menu order
get_filter_taxonomy_slug()
Get the taxonomy slug for a filter (works for both Taxonomy and Attribute types).
private
get_filter_taxonomy_slug(Filter $filter_instance) : string|null
Parameters
- $filter_instance : Filter
-
The filter instance
Return values
string|null —The taxonomy slug or null if not found
is_taxonomy_based_filter()
Check if a filter is taxonomy-based (Taxonomy or Attribute type).
private
is_taxonomy_based_filter(Filter $filter_instance) : bool
Parameters
- $filter_instance : Filter
-
The filter instance
Return values
bool —True if the filter is taxonomy-based