Tweak to structure when getting terms ordered by parent Closes #4729

This commit is contained in:
Mike Jolley 2014-02-12 11:47:56 +00:00 committed by Coen Jacobs
parent cbeb3f48c5
commit 8d3c05f768
1 changed files with 8 additions and 5 deletions

View File

@ -33,26 +33,29 @@ function wc_get_product_terms( $product_id, $taxonomy, $args = array() ) {
// Support ordering by parent // Support ordering by parent
if ( ! empty( $args['orderby'] ) && $args['orderby'] == 'parent' ) { if ( ! empty( $args['orderby'] ) && $args['orderby'] == 'parent' ) {
$fields = isset( $args['fields'] ) ? $args['fields'] : 'all'; $fields = isset( $args['fields'] ) ? $args['fields'] : 'all';
$orderby_parent = true;
// Unset for wp_get_post_terms
unset( $args['orderby'] ); unset( $args['orderby'] );
unset( $args['fields'] ); unset( $args['fields'] );
}
$terms = wp_get_post_terms( $product_id, $taxonomy, $args ); $terms = wp_get_post_terms( $product_id, $taxonomy, $args );
if ( ! empty( $orderby_parent ) ) {
usort( $terms, '_wc_get_product_terms_parent_usort_callback' ); usort( $terms, '_wc_get_product_terms_parent_usort_callback' );
switch ( $fields ) { switch ( $fields ) {
case 'names' : case 'names' :
$terms = wp_list_pluck( $terms, 'name' ); $terms = wp_list_pluck( $terms, 'name' );
break;
case 'ids' : case 'ids' :
$terms = wp_list_pluck( $terms, 'term_id' ); $terms = wp_list_pluck( $terms, 'term_id' );
break;
case 'slugs' : case 'slugs' :
$terms = wp_list_pluck( $terms, 'slug' ); $terms = wp_list_pluck( $terms, 'slug' );
break;
} }
} else {
$terms = wp_get_post_terms( $product_id, $taxonomy, $args );
} }
return $terms; return $terms;