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

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

Related posts

Leave a Reply

3 comments

  1. 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;
      }