For the sake of the example, I'll assume you to have copied the relevant Table to the WordPress DB, to have named it wp_my_xtra_table
and it to contain 3 columns (id,num_val,str_val).
function wpse106832_shortcode_demo( $atts ) {
global $wpdb;
extract( shortcode_atts( array(
'id' => 1
), $atts ) );
$table_row = $wpdb->get_row(
'SELECT * ' .
'FROM ' . $wpdb->prefix . '_my_xtra_table'my_xtra_table ' .
'WHERE id = ' . $id, ARRAY_A
);
if ( ! empty( $table_row ) ) {
return '<table><tr>' .
'<th>ID</th>' .
'<th>Numeric Value</th>' .
'<th>String Value</th>' .
'</tr>' .
'<tr>' .
'<td>' . $table_row['id'] . '</td>' .
'<td>' . $table_row['num_val'] . '</td>' .
'<td>' . $table_row['str_val'] . '</td>' .
'</tr></table>';
} else {
return '<p>Nothing found.</p>';
}
}
add_shortcode( 'wpse106832', 'wpse106832_shortcode_demo' );
With the above, [wpse106832 id=3]
will display your third database entry.
Related Reading
- The Shortcode API
add_shortcode
- The
WPDB
class