WC_CSV_Exporter::format_term_ids
Format term ids to names.
Method of the class: WC_CSV_Exporter{}
No Hooks.
Returns
String.
Usage
$WC_CSV_Exporter = new WC_CSV_Exporter(); $WC_CSV_Exporter->format_term_ids( $term_ids, $taxonomy );
- $term_ids(array) (required)
- Term IDs to format.
- $taxonomy(string) (required)
- Taxonomy name.
Changelog
| Since 3.1.0 | Introduced. |
WC_CSV_Exporter::format_term_ids() WC CSV Exporter::format term ids code WC 10.5.0
public function format_term_ids( $term_ids, $taxonomy ) {
$term_ids = wp_parse_id_list( $term_ids );
if ( ! count( $term_ids ) ) {
return '';
}
$formatted_terms = array();
if ( is_taxonomy_hierarchical( $taxonomy ) ) {
foreach ( $term_ids as $term_id ) {
$formatted_term = array();
$ancestor_ids = array_reverse( get_ancestors( $term_id, $taxonomy ) );
foreach ( $ancestor_ids as $ancestor_id ) {
$term = get_term( $ancestor_id, $taxonomy );
if ( $term && ! is_wp_error( $term ) ) {
$formatted_term[] = $term->name;
}
}
$term = get_term( $term_id, $taxonomy );
if ( $term && ! is_wp_error( $term ) ) {
$formatted_term[] = $term->name;
}
$formatted_terms[] = implode( ' > ', $formatted_term );
}
} else {
foreach ( $term_ids as $term_id ) {
$term = get_term( $term_id, $taxonomy );
if ( $term && ! is_wp_error( $term ) ) {
$formatted_terms[] = $term->name;
}
}
}
return $this->implode_values( $formatted_terms );
}