• Resolved antl19

    (@antl19)


    I’m trying to retrieve data from a simple WP data table I created. The table definitely exists and the short code is [wpdatatable id=1] but when trying the code below i continue to see “no data is found”

    I think I’m using the wrong table name in the code below but not sure. Any help would be much appreciated.

    <?php
    /*
    Plugin Name: Table Test Plugin
    Description: A simple plugin to test fetching data from a wpDataTables table.
    */
    
    // Shortcode for displaying table data
    function table_test_display_shortcode() {
        ob_start();
    
        // I thought '1' is  the right  ID but not sure
        $table_id = 1;
    
        // Load wpDataTables plugin class
        if (class_exists('WPDataTable')) {
            // Get the wpDataTables object
            $wpdt = new WPDataTable($table_id);
    
            // Get the table data
            $table_data = $wpdt->get_data();
    
            if ($table_data) {
                echo '<table>';
                echo '<tr>';
                foreach ($table_data[0] as $column_name => $value) {
                    echo '<th>' . $column_name . '</th>';
                }
                echo '</tr>';
    
                foreach ($table_data as $row) {
                    echo '<tr>';
                    foreach ($row as $value) {
                        echo '<td>' . $value . '</td>';
                    }
                    echo '</tr>';
                }
                echo '</table>';
            } else {
                echo 'No data found.';
            }
        } else {
            echo 'wpDataTables plugin is not activated.';
        }
    
        return ob_get_clean();
    }
    add_shortcode('table_test_display', 'table_test_display_shortcode');
Viewing 1 replies (of 1 total)
  • Plugin Author wpDataTables

    (@wpdatatables)

    Hello,
    are you using the Lite version of our Plugin or Premium?
    And if you can confirm what is this table type that you are trying to pull the data for in this use case?
    If this is a Simple Table type,
    or any table type from the wpDataTables Lite version, such as a table linked to CSV, Excel, etc;

    These “non-server-side” datatables are not saved in your database like our Manual tables ( they are not available in the Lite version),
    but instead, their data is stored in a database table named wp_wpdatatables_rows.
    So, pulling data from the database through any kind of SQL Query on your website ( through your Database Management Tool or PHP code)
    is a bit more complex because this database table stores data in JSON format, not like manual tables (columns * rows).

    In other words, we do not have any built-in way to achieve this with tables made by the Lite Plugin version.
    Of course, if you have coding knowledge or your own developer,
    you can try to go for a custom solution,
    but that is not covered by our Support.

    In case If you have premium wpDataTables, or if you are interested in any workarounds that might be possible with the premium version,
    please open a ticket on our main Support platform here,

     and one of our Agents will respond as quickly as possible to advise if they have any workarounds.

    Premium products are not supported in these forums, as per this comment by ww.wp.xz.cn moderators.

    Thank you for understanding. 

    Kind regards.

    • This reply was modified 2 years, 10 months ago by wpDataTables.
Viewing 1 replies (of 1 total)

The topic ‘retrieving data from wpdatatable’ is closed to new replies.