Support

Account

Home Forums Front-end Issues Hide empty table rows

Solving

Hide empty table rows

  • I have a table that outputs the fields of a group. The problem I have is that I want table rows with no data to be hidden. So only the table rows with content/data is displayed.

    I´ve tried a couple of different variations, but no luck. Any ideas of how to do this? 🙂

    Here is the latest code I´ve been testing:

    <?php if( have_rows('productfact') ): ?>
    <table class="table table-striped table-hover">
      <tbody>
    	<?php if( have_rows('productfact') ): ?>
        	<?php while( have_rows('productfact') ): the_row(); ?>
        <tr>
          <td>Weight</td>
          <td><?php the_sub_field('weight'); ?></td>
        </tr>
        	<?php endwhile;
    	    	else :
    	    	endif; ?>
        	<?php if( have_rows('productfact') ): ?>
            <?php while( have_rows('productfact') ): the_row(); ?>
        <tr>
          <td>Dimensions</td>
          <td><?php the_sub_field('dimensions'); ?></td>
        </tr>
        	<?php endwhile;
    	    	else :
    	    	endif; ?>
      </tbody>
    </table>
    
    <?php endif; ?> 
    
  • 
    <?php 
      if (have_rows('productfact')) :
        while (have_rows('productfact')) :
          if (get_sub_field('weight')) :
            ?>
              <tr>
                <td>Weight</td>
                <td><?php the_sub_field('weight'); ?></td>
              </tr>
            <?php 
          endif;
          // ********* code continues
    
  • Thanks for your response John! Appreciated!

    Unfortunately it didn´t work.

    Should there be a “-character on line 4 in your example?

  • that is a typo, should be :
    It’s really only an example to show you to add an if statement around the table row

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.