Support » Plugin: Advanced Custom Fields: Table Field » Shortcodes in Table // apply_filters('the_content')

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Johann Heyne

    (@jonua)

    The filter “the_content” filters the WordPress editors content only. If you want to do shortcodes on fields, you have to use the function do_shortcode() at the fields content.

    <?php
    
    	$table = get_field( 'table' );
    
    	if ( $table ) {
    
    		echo '<table border="0">';
    
    			if ( $table['header'] ) {
    
    				echo '<thead>';
    
    					echo '<tr>';
    
    						foreach ( $table['header'] as $th ) {
    
    							echo '<th>';
    								echo do_shortcode( $th['c'] );
    							echo '</th>';
    						}
    
    					echo '</tr>';
    
    				echo '</thead>';
    			}
    
    			echo '<tbody>';
    
    				foreach ( $table['body'] as $tr ) {
    
    					echo '<tr>';
    
    						foreach ( $tr as $td ) {
    
    							echo '<td>';
    								echo do_shortcode( $td['c'] );
    							echo '</td>';
    						}
    
    					echo '</tr>';
    				}
    
    			echo '</tbody>';
    
    		echo '</table>';
    	}
    
    ?>

    Uhm, well, thanks. But now, I’m not longer able to put something into the table, the table on the page site disappeared but the custom field name is still there.

    Well, I found the bug. If there is a blank like “Test Test” or “test_test” in the CF, then the table is gone, idk why.

    But I’m still not able to see the table on my page.

    Plugin Author Johann Heyne

    (@jonua)

    Sorry, but I have no idea what your problem is. Please provide more details. What you mean with blank and “test_test” in the custom field?

    <?php
    
    							$table = get_field( 'ddr' );
    							if ( $table ) {
    								echo '<table class="table table-striped" border="0">';
    									if ( $table['header'] ) {
    										echo '<thead>';
    											echo '<tr>';
    
    												foreach ( $table['header'] as $th ) {
    													echo '<th>';
    														echo do_shortcode( $th['c'] );
    													echo '</th>';
    												}
    
    											echo '</tr>';
    										echo '</thead>';
    									}
    
    									echo '<tbody>';
    
    										foreach ( $table['body'] as $tr ) {
    											echo '<tr>';
    
    												foreach ( $tr as $td ) {
    													echo '<td>';
    														echo do_shortcode( $td['c'] );
    													echo '</td>';
    												}
    
    											echo '</tr>';
    										}
    
    									echo '</tbody>';
    								echo '</table>';
    							}
    						?>

    That’s my code right now, but it doesn’t show anything.

    Plugin Author Johann Heyne

    (@jonua)

    Watch the screencast https://www.screenr.com/SloN. Your code should work. If not, I need more details about.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Shortcodes in Table // apply_filters('the_content')’ is closed to new replies.