Support

Account

Home Forums Add-ons Repeater Field Adding together number values

Helping

Adding together number values

  • First things first, a little bit about the project:

    I’m trying to create a “Timesheet system” with the custom fields: Client (Field Type: page_link), Hours (Field Type: number) and Message box (Field Type: textarea). However, since employees should be able to fill out more jobs than one on the same date, I have decided to use “Repeater Field” (I also tested the Flexible Content Field for this).

    The first question will then be:

    01. Is it even possible?

    02. If yes: How can I + together hours inside the same “Repeater Field”?

    In addition, to make it even more difficult:
    Since a month contains up to 31 days it will be 31 different “Repeater Field” on the same post.

    03. How do I calculate all these different “Repeater Field” correctly?

    Note:
    I first tried to make this by using regular Custom Fields, something that’s working great. The problem is of course that it is often more jobs on the same day and for different clients. That is why I hope the “Repeater Field” will work in a similar way as this:

    <h3>Testing</h3>     
            <p>01.01 -2014 - <?php the_field('name_test_01'); ?> t</p>
            <p>01.01 -2014 - <?php the_field('name_test_02'); ?> t</p>
            <p>01.01 -2014 - <?php the_field('name_test_03'); ?> t</p>
            <hr />        
    Til sammen: <?php $variable = get_field('name_test_01') + get_field('name_test_02') + get_field('name_test_03'); ?>
            <?php echo $variable; ?> t

    I hope it’s possible to figure out how to make this work, all help will be highly appreciated!

    PS.
    Please show code examples, I have only just started with PHP (maybe not the best project to start with, but I’m learning best by doing 😉 )

    PS. PS.
    I have used this plugin for some years now, and I’m just so happy for how this plugin evolving and getting better and better. Keep up the great work! 🙂

  • Hi @luna

    The repeater field is well documented with code examples here:
    http://www.advancedcustomfields.com/resources/field-types/repeater/

    You will see that you need to create a loop which iterates over the repeater field’s rows of data.

    You can then use a function called get_sub_field WITHIN the loop, to increase a variable of your choosing.

    Thanks
    E

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

The topic ‘Adding together number values’ is closed to new replies.