How to handle sql with Custom List Table Example

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);

3 Answers
3

$data = $wpdb->get_results($sql, ARRAY_A);

Adding ARRAY_A forces get_results to return an associative array.

Leave a Comment