wc_get_object_terms refactored

This commit is contained in:
Khan M Rashedun-Naby 2018-05-15 15:44:32 +06:00
parent 6c1234668a
commit 5c0d7292f3
1 changed files with 3 additions and 7 deletions

View File

@ -25,15 +25,11 @@ function wc_get_object_terms( $object_id, $taxonomy, $field = null, $index_key =
// Test if terms exists. get_the_terms() return false when it finds no terms. // Test if terms exists. get_the_terms() return false when it finds no terms.
$terms = get_the_terms( $object_id, $taxonomy ); $terms = get_the_terms( $object_id, $taxonomy );
if ( $terms && ! is_wp_error( $terms ) ) { if ( ! $terms || is_wp_error( $terms ) || is_null( $field ) ) {
if ( ! is_null( $field ) ) { return array();
$terms = wp_list_pluck( $terms, $field, $index_key );
}
} else {
$terms = array();
} }
return $terms; return wp_list_pluck( $terms, $field, $index_key );
} }
/** /**