Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Igor Jerosimi?

    (@x64igor)

    I’m afraid you can’t use defined order with that function as it does not support specifying order.

    You can add this sort function which uses sort order from my plugin to your functions.php file:

    function get_the_terms_sort( $terms, $post_id, $taxonomy ) {
    	function cmp_by_custom_order( $a, $b ) {
    		return $a->custom_order - $b->custom_order;
    	}
    	usort( $terms, 'cmp_by_custom_order' );
    
    	return $terms;
    }
    add_filter( 'get_the_terms', 'get_the_terms_sort', 10, 3 );

    Thread Starter c00kiemon5ter

    (@c00kiemon5ter)

    Thanks, this seems to work just fine ??

    Thread Starter c00kiemon5ter

    (@c00kiemon5ter)

    for anyone interested I changed the function a bit to be used just like get_the_terms(..)

    function get_the_terms_sorted( $post_id, $taxonomy ) {
    	$terms = get_the_terms( $post_id, $taxonomy );
    	function cmp_by_custom_order( $a, $b ) {
    		return $a->custom_order - $b->custom_order;
    	}
    	if ( $terms ) usort( $terms, 'cmp_by_custom_order' );
    	return $terms;
    }
    Plugin Author Igor Jerosimi?

    (@x64igor)

    Thanks for sharing your code.

    For anyone needing this functionality:
    My way will sort terms for every call to get_the_terms function, even from plugins and WordPress code so it could be useful in some situations, but on the other hand it will add unnecessary overhead. So I would recommend that you first try c00kiemon5ter’s function.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘use with get_the_terms’ is closed to new replies.