/*Codigo para anadir en el functions.php*/
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 .= '
';
if ( ! empty( $table['caption'] ) ) {
echo '' . $table['caption'] . '';
}
if ( $table['header'] ) {
$return .= '';
$return .= '';
foreach ( $table['header'] as $th ) {
$return .= '| ';
$return .= $th['c'];
$return .= ' | ';
}
$return .= '
';
$return .= '';
}
$return .= '';
foreach ( $table['body'] as $tr ) {
$return .= '';
foreach ( $tr as $td ) {
$return .= '| ';
$return .= $td['c'];
$return .= ' | ';
}
$return .= '
';
}
$return .= '';
$return .= '
';
}
return $return;
}
add_shortcode( 'tablefield', 'shortcode_acf_tablefield' );
/*Shortcode para mostrar la table en la página*/
[tablefield field-name="packing" table-class="my-table"]