Skip to content

Instantly share code, notes, and snippets.

@jmabbas
Created January 6, 2026 14:10
Show Gist options
  • Select an option

  • Save jmabbas/0132a4a69cc935a8f9ed9b099a0aa410 to your computer and use it in GitHub Desktop.

Select an option

Save jmabbas/0132a4a69cc935a8f9ed9b099a0aa410 to your computer and use it in GitHub Desktop.
Electro - Home v5 category block order
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