Support

Account

Home Forums General Issues get_terms orderby custom field

Helping

get_terms orderby custom field

  • Hi I currently have the following which pulls down the product taxonomies but I can’t figure out if I can adapt the following to order by my custom field for each taxonomy called ‘order’ they each have a number I’m just not sure how to adapt the following. Any pointers much appreciated, cheers.

    
    <?php
    $terms = get_terms("product_cat");
    if ( !empty( $terms ) && !is_wp_error( $terms ) ){
    foreach ( $terms as $term ) { ?>
    
  • The short answer is that you can’t order your terms by a custom meta field unless you loop through them and create your own array of objects in that order.

    However since you say they each have a number maybe this number is just so you can order them the way you want and nothing else really. If so you can use a plugin like this: https://wordpress.org/plugins/taxonomy-order/
    There are also other plugins that do the same thing I just grabbed the first I could find 🙂

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘get_terms orderby custom field’ is closed to new replies.