retrieving data from wpdatatable
-
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)
Viewing 1 replies (of 1 total)
The topic ‘retrieving data from wpdatatable’ is closed to new replies.