WordPress at a glance
function is not described


DataStore::add_order_by_params() protected WC 1.0

Fills ORDER BY clause of SQL request based on user supplied parameters.

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

No Hooks.


null. Nothing.


// protected - for code of main (parent) or child class
$result = $this->add_order_by_params( $query_args, $from_arg, $id_cell );
$query_args(array) (required)
Parameters supplied by the user.
$from_arg(string) (required)
Target of the JOIN sql param.
$id_cell(string) (required)
ID cell identifier, like table_name.id_column_name.

Code of DataStore::add_order_by_params() WC 5.3.0

protected function add_order_by_params( $query_args, $from_arg, $id_cell ) {
	global $wpdb;
	$lookup_table    = self::get_db_table_name();
	$order_by_clause = $this->add_order_by_clause( $query_args, $this );
	$this->add_orderby_order_clause( $query_args, $this );

	if ( false !== strpos( $order_by_clause, '_terms' ) ) {
		$join = "JOIN {$wpdb->terms} AS _terms ON {$id_cell} = _terms.term_id";
		if ( 'inner' === $from_arg ) {
			// Even though this is an (inner) JOIN, we're adding it as a `left_join` to
			// affect its order in the query statement. The SqlQuery::$sql_filters variable
			// determines the order in which joins are concatenated.
			// See: https://github.com/woocommerce/woocommerce-admin/blob/1f261998e7287b77bc13c3d4ee2e84b717da7957/src/API/Reports/SqlQuery.php#L46-L50.
			$this->subquery->add_sql_clause( 'left_join', $join );
		} else {
			$this->add_sql_clause( 'join', $join );