Support » Plugin: Custom List Table Example » treat data as number for order pusrpose

  • Resolved chlustanec


    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

Viewing 1 replies (of 1 total)
  • chiflon


    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.

Viewing 1 replies (of 1 total)
  • The topic ‘treat data as number for order pusrpose’ is closed to new replies.