Make sort orders affect other get_terms calls Closes #3439.

This commit is contained in:
Mike Jolley 2013-08-19 14:31:48 +01:00
parent 4f6bed2620
commit 16ed6e4faf
2 changed files with 40 additions and 2 deletions

View File

@ -175,7 +175,26 @@ function woocommerce_get_product_terms( $object_id, $taxonomy, $fields = 'all' )
if ( ! is_array( $object_terms ) ) if ( ! is_array( $object_terms ) )
return array(); return array();
$all_terms = array_flip( get_terms( $taxonomy, array( 'menu_order' => 'ASC', 'fields' => 'ids' ) ) ); $args = array( 'fields' => 'ids' );
$orderby = WC()->get_helper( 'attribute' )->attribute_orderby( $taxonomy );
switch ( $orderby ) {
case 'name' :
$args['orderby'] = 'name';
$args['menu_order'] = false;
break;
case 'id' :
$args['orderby'] = 'id';
$args['order'] = 'ASC';
$args['menu_order'] = false;
break;
case 'menu_order' :
$args['menu_order'] = 'ASC';
break;
}
$all_terms = array_flip( get_terms( $taxonomy, $args ) );
switch ( $fields ) { switch ( $fields ) {
case 'names' : case 'names' :

View File

@ -127,7 +127,26 @@ class WC_Widget_Layered_Nav extends WC_Widget {
if ( ! taxonomy_exists( $taxonomy ) ) if ( ! taxonomy_exists( $taxonomy ) )
return; return;
$terms = get_terms( $taxonomy, array( 'hide_empty' => '1' ) ); $get_terms_args = array( 'hide_empty' => '1' );
$orderby = WC()->get_helper( 'attribute' )->attribute_orderby( $taxonomy );
switch ( $orderby ) {
case 'name' :
$get_terms_args['orderby'] = 'name';
$get_terms_args['menu_order'] = false;
break;
case 'id' :
$get_terms_args['orderby'] = 'id';
$get_terms_args['order'] = 'ASC';
$get_terms_args['menu_order'] = false;
break;
case 'menu_order' :
$get_terms_args['menu_order'] = 'ASC';
break;
}
$terms = get_terms( $taxonomy, $get_terms_args );
if ( count( $terms ) > 0 ) { if ( count( $terms ) > 0 ) {