Support

Account

Home Forums Add-ons Repeater Field Display repeater from options page

Solved

Display repeater from options page

  • The repeater field is very simple. It’s only got 3 fields ‘feestdag’ ‘datum’ and ‘einddatum’ (translation: holiday, date and end-date).

    The output should look something like this:
    <table style="width: 100%;">
    <tbody>
    <tr>
    <td> 'feestdag'</td>
    <td>'datum'-'einddatum'</td>
    </tr>
    </tbody>
    </table>

  • Hello Florence!

    Here is 2 possibilities.

    Hope this will help you!

    Option #1

    <?php
    
    /*
    * First option
    */
    $rows = get_field("my_repeat_name", "option");
    
    if($rows){
        foreach($rows as $row){
            echo $row["field_name"];
        }
    }
    
    ?>
    

    Option #2

    
    <?php
    /*
    * Second option
    */
    if(have_rows("my_repeater_name", "option")){
        
        while(have_rows("my_repeater_name", "option")) : the_row();
            
            echo get_sub_field("field_name");
        
        endwhile;
    }
    
    ?>
  • Hello Sam, thank you! I created a shortcode using WP Code plugin with the code below:

    if(have_rows("gesloten", "option")){
        
        while(have_rows("gesloten", "option")) : the_row();
            
            echo get_sub_field("feestdag");
            echo get_sub_field("datum");
            echo get_sub_field("eind-datum");
        
        endwhile;
    }
    
    ?>

    1. How can I now display these fields in the manor I suggested?
    2. There is one field that may sometimes be empty “eind-datum”. If empty, nothing should be shown. Also the dash in front of that date should not be shown. The output should like something like this:

    text-field 12/12/23 – 14/12/23
    text-field 16/12/23
    text-field 19/12/23 – 22/12/23
    text-field 27/12/23
    text-field 29/12/23

    Thank you!

  • Oh, sorry if I was not answer completely. I just understand now. (I need more practice in english hehe)

    Ok, you can play with your PHP like that, but know, you have in fact, multiple ways:

    (I supose you have your date in the format you give me. Let’s me know if it’s a timestamp.)

    
    <?php
    
        if(have_rows("gesloten", "option")){
            
            echo '<table style="width: 100%;">';
            
                echo '<tbody>';
            
                while(have_rows("gesloten", "option")) : the_row();
    
                    $birthDayName = get_sub_field("feestdag");
    
                    $startDate = get_sub_field("datum");
                    $endDate = !empty(get_sub_field("eind-datum")) ? ' - ' . get_sub_field("eind-datum") : null;
                    
                    $startToEndDate = $startDate . $endDate;
    
                    echo '<tr>';
                        echo '<td>'. $birthDayName .'</td>';
                        echo '<td>'. $startToEndDate .'</td>';
                    echo '</tr>';
    
                endwhile;
            
                echo '</tbody>';
            
            echo '</table>';
        }
    
    ?>
    
  • Woah so cool, thank you! I understand what I did wrong now 😀
    I changed the code slightly to make it simpler:

        if(have_rows("gesloten", "option")){
            
            echo '<table style="width: 100%;">';
            
                echo '<tbody>';
            
                while(have_rows("gesloten", "option")) : the_row();
    
                    $feestdag = get_sub_field("feestdag");
    
                    $datumgesloten = get_sub_field("datum");
                    
    
                    echo '<tr>';
                        echo '<td>'. $feestdag .'</td>';
                        echo '<td>'. $datumgesloten .'</td>';
                    echo '</tr>';
    
                endwhile;
            
                echo '</tbody>';
            
            echo '</table>';
        }
    
    ?>

    One last question. How can I style the columns to 50%?
    I tried adding a width=”50%” inside <td> but that did not get me the desired look.

    The top table is how I would like it to look. The bottom table is the current output.

    Tbale column spacing

    Thank you much for this

  • I think you can simply add style=”width: 50%;” in each td element or from your CSS.

    I said “I think” because HTML tables are far behind me and I could be wrong. (I prefer to recreate a table appearance with grid or flex ^^)

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

You must be logged in to reply to this topic.