Hi,
“Tablepress” uses the shortcode [table] which you may also defined to output the tablefield´s table. If so, all you have to do is renaming the shortcode for outputting the tablefield table like add_shortcode( 'tablefield', … );
Cheers,
Johann
hi
you mean in the functions.php?
can you send me an example code please?
Thanks a lot
Uwe
Well, the issue seems to be a name conflict of two shortcodes named “table”. Did you add a code like add_shortcode( 'table', … ); by yourself in the functions.php?
Hi
I currently do use the following code in my functions.php (copied from a support ticket here and modified it to output also the table caption:
function shortcode_acf_tablefield( $atts ) {
$a = shortcode_atts( array(
'field-name' => false,
'post-id' => false,
), $atts );
$table = get_field( $a['field-name'], $a['post-id'] );
$return = '';
if ( ! empty( $table['caption'] ) ) {
$return .= '<div class="table-title">' . $table['caption'] . '</div>';
}
if ( $table ) {
$return .= '<table class="product-tables">';
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( 'table', 'shortcode_acf_tablefield' );
The shortcode I am using to render the table is: [table field-name=”my-tablename”]
Thanks very much for you help in advance
Uwe
I tried to replace all $table with $tabletest but that doesnt seem to work either.
WP display now the shortcode instead of [table “” not found /]
Hope you can help me 🙂
Uwe
Hi,
you must change add_shortcode( 'table', 'shortcode_acf_tablefield' ); into add_shortcode( 'tablefield', 'shortcode_acf_tablefield' ); and then using [tablefield field-name="my-tablename"] to output a tablefields table.
Cheers,
Johann
-
This reply was modified 6 years, 6 months ago by
Johann Heyne.
-
This reply was modified 6 years, 6 months ago by
Johann Heyne.
-
This reply was modified 6 years, 6 months ago by
Johann Heyne.
Hi Johann
awesome – works like charm.
Thanks very much for the fast and good help
Uwe
Hi,
good to hear that you guys found the solution already! 🙂
Best wishes,
Tobias