Home Forums Add-ons Repeater Field How to hide an empty row working with Custom Field Repeater?


How to hide an empty row working with Custom Field Repeater?

  • Hi, I’m working on a project with Custom Field for WordPress. I have this code that works well by showing a list of items. The problem comes when, for example, the first two lines are empty. are displayed. I would like to hide the line when no values ​​are inserted inside them, showing the line with the values. I hope I was clear, every suggestion is accepted. I tried with “if! Empty” showing only the lines with the values ​​inside it but totally changing the place of the div and the layout of the page. Any suggestions? Thank you.

    The code is:

    <div id="main">
    <h2> List </h2>
    <?php if( have_rows('repeater_field') ): 
    $number = 1; { 
    while( have_rows('repeater_field') ): the_row(); ?>
    <div class="maintitle">
    <div class="contenido"><span class="number<?php if ($coun == 0) : ?> <?php endif; $coun++; ?>"><?php echo $number; ?></span>    <span class="title"><?php the_title(); ?> - <?php _e('TitleList') ?> <?php echo $number; ?></span></div>
    <?php if( have_rows('list') ): ?>
    <div class="meo" <?php if ($count == 0) : ?>style="display: block"<?php endif; $count++; ?>>
    <ul class="listin">
    <?php $numberc = 1; { while( have_rows('list') ): the_row(); ?>
    <div class="numberx"><?php echo $number; ?> x <?php echo $numberc ?></div>
    <div class="titlelist">
    <a href="<?php bloginfo('url'); ?>/list/<?php echo get_sub_field('slug'); ?>">
    <?php if($title = get_sub_field('titlee')) { echo $title; } ?> <?php endif; ?>
    <?php $numberc++; ?> 
    <?php endwhile; } ?> 
    <?php endif; ?>
    <?php $number++; ?> 
    <?php endwhile; } ?> 
    <?php endif; ?>
  • You have some issues with the nesting of your code and I could not figure out the problems so that I can edit it. This is basically what you need to do.

    while (have_rows('repeater_field')) {
      // check all sub fields and only display if there are values
      if (get_sub_field('sub_field_1') && get_sub_field('sub_field_1')) {
        // only do this if all sub fields have content
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘How to hide an empty row working with Custom Field Repeater?’ is closed to new replies.