WC_REST_Terms_Controller::compare_terms()protectedWC 1.0

Comparison function for sorting terms by a column.

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

Метод класса: WC_REST_Terms_Controller{}

Хуков нет.

Возвращает

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

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->compare_terms( $left, $right );
$left(stdClass) (обязательный)
Term object.
$right(stdClass) (обязательный)
Term object.

Код WC_REST_Terms_Controller::compare_terms() WC 8.7.0

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 );
}