I am trying to order my terms numeric. But the problem is that nog every term is numeric. So I have the following terms (check image below) which some of them are dimensions and some are others. As you can see, my get_terms()
function, orders them by name, but if they are numeric it only looks at the first character. So 1400mm is less than 500mm.
I don't know where I need to begin. Should I try to modify the result of get_terms()
or hook into the get_terms_orderby() function. But I have no idea how to do this.
My code to show the terms:
<?php
$taxonomy = 'product-filter';
$parents = get_terms( $taxonomy, array( 'hide_empty' => false, 'parent' => 0, 'orderby' => 'id' ) );
if( ! empty( $parents ) ) {
foreach( $parents as $parent ) {
echo '<ul>';
echo '<h2>' . $parent->name . '</h2>';
$children = get_terms( $taxonomy, array( 'hide_empty' => false, 'child_of' => $parent->term_id ) );
foreach( $children as $child ) {
echo '<li><label><input type="checkbox">' . $child->name . ' (' . $child->count . ')</label></li>';
}
echo '</ul>';
}
}
?>