WC_CSV_Exporter::format_term_ids( array $term_ids, string $taxonomy )

Format term ids to names.


Description Description


Parameters Parameters

$term_ids

(Required) Term IDs to format.

$taxonomy

(Required) Taxonomy name.


Top ↑

Return Return

(string)


Top ↑

Source Source

File: includes/export/abstract-wc-csv-exporter.php

416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
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 );
}

Top ↑

Changelog Changelog

Changelog
Version Description
3.1.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.