最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

categories - Woocommerce custom taxonomy order

programmeradmin0浏览0评论

I have a custom order of my taxonomies in Woocommerce/Taxonomy Order.

When I display them, they get printed in alphabetical order.

How can I prevent this behavior and print them in the order I selected?

Thanks in advance!

I have a custom order of my taxonomies in Woocommerce/Taxonomy Order.

When I display them, they get printed in alphabetical order.

How can I prevent this behavior and print them in the order I selected?

Thanks in advance!

Share Improve this question asked Nov 23, 2016 at 11:35 Arno NymoArno Nymo 1 1
  • are you using any plugin or you did it manually using coding ? – GKS Commented Nov 23, 2016 at 11:41
Add a comment  | 

1 Answer 1

Reset to default 0

You may consider using the get_terms() function to generate a list of the items in a custom taxonomy. I'm sure there are other good ways of doing this, but there are plenty of parameters here you can try out to get the order you need.

    $terms = get_terms( 'custom_taxonomy_here', 'orderby=count&hide_empty=0' );
        if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
        echo '<ul>';
        foreach ( $terms as $term ) {
            echo '<li>' . $term->name . '</li>';
        }
        echo '</ul>';
    }

In the example above, orderby orders the terms by their count (but there are other arguments for a different order) and hide_empty to display terms whether or not they are associated with a post.

发布评论

评论列表(0)

  1. 暂无评论