function shortcode_acf_tablefield( $atts ) {
$a = shortcode_atts( array(
'table-class' => '',
'field-name' => false,
'post-id' => false,
), $atts );
$table = get_field( $a['field-name'], $a['post-id'] );
$return = '';
if ( $table ) {
$return .= '<table class="' . $a['table-class'] . '" border="0">';
if ( ! empty( $table['caption'] ) ) {
echo '<caption>' . $table['caption'] . '</caption>';
}
if ( $table['header'] ) {
$return .= '<thead>';
$return .= '<tr>';
foreach ( $table['header'] as $th ) {
$return .= '<th>';
$return .= $th['c'];
$return .= '</th>';
}
$return .= '</tr>';
$return .= '</thead>';
}
$return .= '<tbody>';
foreach ( $table['body'] as $tr ) {
$return .= '<tr>';
foreach ( $tr as $td ) {
$return .= '<td>';
$return .= $td['c'];
$return .= '</td>';
}
$return .= '</tr>';
}
$return .= '</tbody>';
$return .= '</table>';
}
return $return;
}
add_shortcode( 'tablefield', 'shortcode_acf_tablefield' );