Web Hosting
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

WordPress fix Reply To: list Terms with order by

Discussion in 'Misc WordPress Requests' started by Jacob Peattie, Oct 17, 2017.

  1. Jacob Peattie

    Guest

    Reply To: list Terms with order by, by Jacob Peattie

    There’s no argument for get_the_terms() that will sort the results, so you’ll need to get the array of terms and then sort that manually using usort:


    $terms = get_the_terms( get_the_ID(), 'portfolio' );

    if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
    usort( $terms, function( $term_a, $term_b ) {
    return $term_a->term_id - $term_b->term_id;
    } );

    foreach ( $terms as $term ) {
    // Do something.
    }
    }

    Reply To: list Terms with order by
     
    #1

Share This Page

Web Hosting