WC_REST_Terms_Controller::compare_terms
Comparison function for sorting terms by a column.
Uses $this->sort_column to determine field to sort by.
Method of the class: WC_REST_Terms_Controller{}
No Hooks.
Returns
Int. <0 if left is higher "priority" than right, 0 if equal, >0 if right is higher "priority" than left.
Usage
// 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.
WC_REST_Terms_Controller::compare_terms() WC REST Terms Controller::compare terms code WC 10.6.2
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 );
}