Support

Account

Home Forums General Issues Save a Variable in a Custom Field

Helping

Save a Variable in a Custom Field

  • Hi.
    I have some custom fields in my posts that I use to make some additions and I save the results in some variables. I would like to save those variables in custom fields to show them elsewhere.

    This is part of the code, for a better understanding:

    <?php
    $total = 0;
    while(the_repeater_field(‘polizas’ )):
    $total += intval( get_sub_field(‘monto’ ) );
    endwhile;

    $count = 0;
    $polizas = get_field(‘polizas’);
    if (is_array($polizas)) {
    $count = count($polizas);
    }
    echo “<table>”;
    echo “<tr>”;
    echo ” <th>Total$</th>”;
    echo ” <th>Faltan$</th>”;
    echo ” <th>Total#</th>”;
    echo ” <th>Faltan#</th>”;
    echo “</tr>”;
    echo “<tr>”;
    echo “<td>$total</td>”;
    $faltan=300000-$total;
    echo “<td>$faltan</td>”;

    echo “<td>$count</td>”;
    $faltancount=30-$count;
    echo “<td>$faltancount</td>”;
    echo “</tr>”;
    echo “</table>”;
    ?>

    • Jeroen

    • June 19, 2019 at 7:11 pm

    You can update field values with update_field.

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.