0

I got stuck with ordering custom taxonomy. I've created a hierarchical custom taxonomy called Brand and created some meta tags including one called position. Now I would like to display my terms ordered by position meta tag. I tried doing this:

<?php
$taxonomy = 'brand';
    $term_args=array(
        'hide_empty' => false,
        'orderby'   => 'meta_value_num',
        'meta_key' => 'position',
        'parent' => 0,
    );
?>

<?php $tax_terms = get_terms($taxonomy, $
<?php foreach ( $tax_terms as $tax_term ) : ?>
    <h2><?php echo $tax_term->name; ?></h2>
<?php endforeach; ?>

But as I can see get_terms() doesn't support 'orderby' = 'meta_value_num' and terms are ordered by name. Is there any way to display them ordered by position?

Thanks for your help! Patryk

  • And the position field is just a number correct? – deflime Jan 28 '15 at 21:30
0

Assuming the position field is filled with numbers to give order: have a look at ksort.

<?php 

            $terms = get_terms('brands');

            // Let's create our own array and then reorder it
            $order_terms = array();
            foreach( $terms as $term ) {
                $position = set_up_the_position_meta_here;
                $order_terms[$position] ='<h2>'.$term->name.'</h2>';
            }

            // now lets reorder the array based on keys (position)
            ksort($order_terms);

            // time to display
            foreach( $order_terms as $order_term ) {
                echo $order_term;
            }

        ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.