Created
January 6, 2026 14:10
-
-
Save jmabbas/0132a4a69cc935a8f9ed9b099a0aa410 to your computer and use it in GitHub Desktop.
Electro - Home v5 category block order
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| add_filter( 'get_terms', 'electro_preserve_category_slug_order', 10, 4 ); | |
| function electro_preserve_category_slug_order( $terms, $taxonomies, $args, $term_query ) { | |
| if ( | |
| is_admin() | |
| || empty( $args['include'] ) | |
| || ! in_array( 'product_cat', (array) $taxonomies, true ) | |
| ) { | |
| return $terms; | |
| } | |
| $include = array_map( 'intval', (array) $args['include'] ); | |
| usort( $terms, function ( $a, $b ) use ( $include ) { | |
| return array_search( $a->term_id, $include ) | |
| <=> array_search( $b->term_id, $include ); | |
| }); | |
| return $terms; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment