I am using the Custom List Table Example plugin as a base to display entries from a table I created in the wordpress database…
However I am having issues with this function
function column_default($item, $column_name){
}
I get the error message:
Fatal error: Cannot use object of type stdClass as array in
In the example in the plugin, it uses a simple array. But the $data returned from the query returns several rows of data (i.e. an array with object, object, object).
Inside of my prepare_items() function:
global $wpdb;
$orderby = (!empty($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : 'name'; //If no sort, default to title
$sql = "SELECT * FROM wp_nc_location ORDER BY " . $orderby;
$data = $wpdb->get_results($sql);
Adding
ARRAY_A
forcesget_results
to return an associative array.This is what I use to retrieve data from custom tables:
Got it working by passing $item as an array