array key: get_data
returns: array of array
The get_data
array returns the rows of data to be displayed and used in list table processing generally called items in list table construction. The array is returned in rows of associative arrays with the associative keys corresponding to the keys of the columns array. This array of arrays can correspond directly to a $wpdb
result set if the result set is returned in ARRAY_A
format. This array and database query must also account for pagination and any search terms or WHERE
clauses. These parameters can be brought into the callable via query string.
WordPress $wpdb
documentation available at https://codex.wordpress.org/Class_Reference/wpdb
$list_table_definitions['get_data'] = 'saturn_tables_cars_return_items';
function saturn_tables_cars_return_items($per_page, $page_number) { global $wpdb; $offset = ($per_page * ($page_number -1)); $orderby_clause = ""; if (isset($_GET['orderby']) && isset($_GET['order'])) { $orderby = esc_sql($_GET['orderby']); $order = esc_sql($_GET['order']); $orderby_clause = "ORDER BY $orderby $order"; } $where_clause[] = 1; if (isset($_GET['status'])) { $status = ($_GET['status'] == "trash") ? 1 : 0; $where_clause[] = "status = $status"; } else { $where_clause[] = "status = 0"; } if (isset($_GET['s'])) { $search = esc_sql($_GET['s']); $where_clause[] = "CONCAT_WS(' ', make, model) LIKE '%$search%'"; } if (isset($_GET['make'])) { $make = esc_sql($_GET['make']); $where_clause[] = ($make == "All Makes") ? 1 : "make = '$make'"; } $where_clause = implode(" AND ", $where_clause); $query = "SELECT id, make, model, mpg, cylinders, weight, model_year, country FROM saturn_tables_cars WHERE $where_clause $orderby_clause LIMIT $per_page OFFSET $offset"; $items = $wpdb->get_results($query, ARRAY_A); $wpdb->flush(); return $items; }