从自定义字段获取table到前端
Published
2023-03-23
浏览次数 : 140
// Get the table data for the current post
$table_data = get_post_meta( get_the_ID(), '_my_table_data', true );
// Display the table
if ( $table_data ) {
echo '<table>';
echo '<thead><tr><th>管径</th><th>孔距</th><th>排距</th></tr></thead>';
echo '<tbody>';
foreach ( $table_data as $index => $row ) {
echo '<tr>';
echo '<td>' . esc_html( $row['column_1'] ) . '</td>';
echo '<td>' . esc_html( $row['column_2'] ) . '</td>';
echo '<td>' . esc_html( $row['column_3'] ) . '</td>';
echo '</tr>';
}
echo '</tbody>';
echo '</table>';
}