• Resolved captainjk

    (@captainjk)


    I am having trouble displaying the table inside of a flexible content field. Currently, it displays nothing, but if I remove the if ( ! empty ( $table ) ) it will display empty table cells with no content. I tested the code (table code, copy/pasted directly from the plugin page with my field name inserted) outside of the flexible content field and the table works fine. How can I get the table to work inside the flexible content field?

    
    <?php 
    global $post;
    $page_id = get_queried_object_id();
    
    if( have_rows('page_content', $page_id) ): ?>
    
       <?php while ( have_rows('page_content', $page_id) ) : the_row(); ?>
    
    <!-- Other Content Blocks -------- -->
    
          <?php elseif( get_row_layout() == 'product_table' ): ?>
    <?php
    $table = get_field( 'table_block' );
    
    if ( ! empty ( $table ) ) {
    
        echo '<table border="0">';
    
            if ( ! empty( $table['caption'] ) ) {
    
                echo '<caption>' . $table['caption'] . '</caption>';
            }
    
            if ( ! empty( $table['header'] ) ) {
    
                echo '<thead>';
    
                    echo '<tr>';
    
                        foreach ( $table['header'] as $th ) {
    
                            echo '<th>';
                                echo $th['c'];
                            echo '</th>';
                        }
    
                    echo '</tr>';
    
                echo '</thead>';
            }
    
            echo '<tbody>';
    
                foreach ( $table['body'] as $tr ) {
    
                    echo '<tr>';
    
                        foreach ( $tr as $td ) {
    
                            echo '<td>';
                                echo $td['c'];
                            echo '</td>';
                        }
    
                    echo '</tr>';
                }
    
            echo '</tbody>';
    
        echo '</table>';
    }
    ?>
    
          <?php endif; ?>
    
       <?php endwhile; ?>
       <?php wp_reset_query(); ?>
       <?php wp_reset_postdata(); ?>
    
    <?php else: ?>
    <?php endif; ?>
    
    
    • This topic was modified 3 years, 4 months ago by captainjk.
Viewing 1 replies (of 1 total)
  • Thread Starter captainjk

    (@captainjk)

    Figured it out. Needed to change $table = get_field( 'table_block' ); to $table = get_sub_field( 'table_block' );. Works great now!

Viewing 1 replies (of 1 total)
  • The topic ‘Table not showing when inside Flexible Content Field’ is closed to new replies.