How get data from specific cell tablepress
-
Is there any way to retrieve data from a specific cell in one of the tablepress tables?
Updated
I tried creating a custom shortcode that accesses a specific cell of a specific table. I’m not sure if the approach is correct, but I was able to get the data.
function load_specific_cell_data($atts) {
// Define shortcode attributes
$atts = shortcode_atts(
array(
'table_id' => '', // ID table
'row' => '1', // Line number (numbering from 1)
'column' => '1', // Column number (numbering from 1)
),
$atts
);
// Check that the table ID is passed
if (empty($atts['table_id'])) {
return 'The table ID is not specified.';
}
// Check that TablePress is active
if (class_exists('TablePress_Table_Model')) {
// Load the table model
$model_table = new TablePress_Table_Model();
// Load table by ID
$table = $model_table->load($atts['table_id']);
// Check that the table exists and contains data
if (is_array($table) && isset($table['data'])) {
// Convert row and column numbers to indices (numbering from 0)
$row = intval($atts['row']) - 1;
$column = intval($atts['column']) - 1;
// Check if there is data in the specified row and column
if (isset($table['data'][$row][$column])) {
// Return cell value
return esc_html($table['data'][$row][$column]);
} else {
return 'No data found in string ' . ($row + 1) . ', column ' . ($column + 1);
}
} else {
return 'Table with ID ' . esc_html($atts['table_id']) . ' was not found or does not contain any data.' ;
}
} else {
return 'TablePress is not installed or active.';
}
}
add_shortcode('get_table_cell', 'load_specific_cell_data');
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘How get data from specific cell tablepress’ is closed to new replies.