Automattic\WooCommerce\Admin\API\Reports
DataStore::get_ids_table
Generates a virtual table given a list of IDs.
Method of the class: DataStore{}
No Hooks.
Returns
Array.
Usage
// protected - for code of main (parent) or child class $result = $this->get_ids_table( $ids, $id_field, $other_values );
- $ids(array) (required)
- Array of IDs.
- $id_field(array) (required)
- Name of the ID field.
- $other_values(array)
- Other values that must be contained in the virtual table.
Default:array()
DataStore::get_ids_table() DataStore::get ids table code WC 11.0.1
protected function get_ids_table( $ids, $id_field, $other_values = array() ) {
global $wpdb;
$selects = array();
foreach ( $ids as $id ) {
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$new_select = $wpdb->prepare( "SELECT %s AS {$id_field}", $id );
foreach ( $other_values as $key => $value ) {
$new_select .= $wpdb->prepare( ", %s AS {$key}", $value );
}
// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
array_push( $selects, $new_select );
}
return join( ' UNION ', $selects );
}