wc_set_term_order( int $term_id, int $index, string $taxonomy, bool $recursive = false )

Set the sort order of a term.


Description Description


Parameters Parameters

$term_id

(Required) Term ID.

$index

(Required) Index.

$taxonomy

(Required) Taxonomy.

$recursive

(Optional) Recursive (default: false).

Default value: false


Top ↑

Return Return

(int)


Top ↑

Source Source

File: includes/wc-term-functions.php

function wc_set_term_order( $term_id, $index, $taxonomy, $recursive = false ) {

	$term_id = (int) $term_id;
	$index   = (int) $index;

	update_term_meta( $term_id, 'order', $index );

	if ( ! $recursive ) {
		return $index;
	}

	$children = get_terms( $taxonomy, "parent=$term_id&hide_empty=0&menu_order=ASC" );

	foreach ( $children as $term ) {
		$index++;
		$index = wc_set_term_order( $term->term_id, $index, $taxonomy, true );
	}

	clean_term_cache( $term_id, $taxonomy );

	return $index;
}


Top ↑

User Contributed Notes User Contributed Notes

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