WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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);
share|improve this question
I think the problem is in the IF statement. Try just using $sql = "SELECT * FROM wp_nc_location ORDER BY title. – Steven Aug 15 '11 at 21:28
Nope. Still the same error – redconservatory Aug 15 '11 at 21:30
Please post the whole function and add echo '<pre>'; var_dump($data); echo '</pre>'; add the end to it and post the result. – kaiser Aug 15 '11 at 22:09
You may wish to take a look at the example plugin to get a better grasp of how to use the class. – t31os Aug 16 '11 at 11:59
$data = $wpdb->get_results($sql, ARRAY_A);

Adding ARRAY_A forces get_results to return an associative array.

share|improve this answer

This is what I use to retrieve data from custom tables:

  // Retrieve all seasons registered
  function get_registered_seasons() {
    global $wpdb;

    $table_name   = $wpdb->prefix . "cwgallery";    
    $sql          = "SELECT DISTINCT year, season FROM $table_name ORDER BY year DESC ";
    $result  = $wpdb->get_results($sql);

    return $result;
share|improve this answer
When I print_f on my $data it's showing my data (in array form)...so that part is working. My problem is that I am not very familiar with the built-in Wordpress Class to List a table in the admin section... – redconservatory Aug 15 '11 at 21:39
up vote 0 down vote accepted

Got it working by passing $item as an array

function column_default($item, $column_name){
$item = (array)($item)
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.