I’m not entirely sure if that’s what you wanted, but… Here’s the code that will register a shortcode, which will get given row and output all the fields of it:
function shortcode_db_row_cb( $atts ) {
$atts = shortcode_atts( array(
'id' => false,
), $atts, 'db_row' );
global $wpdb;
$row = $wpdb->get_row( $wpdb->prepare( "select * from {$wpdb->prefix}TABLE_NAME where id = %d", $atts['id'] ), ARRAY_A );
$res="";
if ( $row ) {
$res="<table>";
$res .= '<tr>';
foreach ( $row as $k => $v ) $res .= '<th>' . esc_html($k) . '</th>';
$res .= '</tr>';
$res .= '<tr>';
foreach ( $row as $k => $v ) $res .= '<to>' . esc_html($v) . '</td>';
$res .= '</tr>';
$res .= '</table>';
return $res;
}
return 'no such row';
}
add_shortcode( 'db_row', 'shortcode_db_row_cb' );