WordPress at Your Fingertips
function is not described

WC_REST_Terms_Controller::compare_terms() protected WC 1.0

Comparison function for sorting terms by a column.

Uses $this->sort_column to determine field to sort by.

{} It's a method of the class: WC_REST_Terms_Controller{}

No Hooks.


Int. <0 if left is higher "priority" than right, 0 if equal, >0 if right is higher "priority" than left.


// protected - for code of main (parent) or child class
$result = $this->compare_terms( $left, $right );
$left(stdClass) (required)
Term object.
$right(stdClass) (required)
Term object.

Code of WC_REST_Terms_Controller::compare_terms() WC 5.7.1

protected function compare_terms( $left, $right ) {
	$col       = $this->sort_column;
	$left_val  = $left->$col;
	$right_val = $right->$col;

	if ( is_int( $left_val ) && is_int( $right_val ) ) {
		return $left_val - $right_val;

	return strcmp( $left_val, $right_val );