Custom List Table Example
[resolved] treat data as number for order pusrpose (2 posts)

  1. chlustanec
    Posted 2 years ago #

    I have tables created with the help of this plugin/tutorial. However I cannot make them to treate numeric data as numeric data. So when I order the column with IDs, it is orderd like 1,10,11,12,2,3,4,5,6...

    data is pulled from database, ID is int. I even tried to add 0 during query, add 0 during feeding the table, tried +1-1 on both occasion as well, but those are still treated as string.

    Do anybody have any idea how to fix it? :) thanks


  2. chiflon
    Posted 2 years ago #

    it happens because the sorting it's based on arrays
    To sort on database data, you must to include in SQL query:

    private function table_data()
        global $wpdb;
        // Set defaults
        $orderby = 'razon';
        $order = 'asc';
        // If orderby is set, use this as the sort column
            $orderby = $_GET['orderby'];
        // If order is set use this as the order
            $order = $_GET['order'];
        $sql = "SELECT * FROM ".DB_TABLE." ORDER BY ".$orderby." $order";
        $data = $wpdb->get_results($sql, ARRAY_A);
        return $data;

    Replace line 363
    $data = $this->example_data;
    $data = $this->table_data();

    Finnaly delete the usort_reorder() and usort functions.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Custom List Table Example
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic