• Hello. I have a question.
    I have 3 custom-fileds, for example is “gain”, “spent” and “total”.
    I want to fill “total” automatically, like “gain – spent = total”.

    Function “get_post_meta” works not correctly in that case, cause it get meta-value after I click “publicate” and I need click “update” again.

    I need some help. How can I got value in custom-field “total” from other meta-values.

    Sry for my English. =)

Viewing 1 replies (of 1 total)
  • I’m going to be trying something like this soon – was checking to see if some else had already solved it.

    I tink that “Total” will not be a custom field. It will be echoed back to the screen in the front-end view – yes, after the page is updated.
    In a custom page template I’d try something like this:

    <?php
    $gain=(get_post_meta($post->ID, 'gain', true));
    $spent=(get_post_meta($post->ID, 'spent', true));
    $total=($gain-$spent);?>
    <p>The total remaining  balance is: $<?php echo($total);?></p>

    Or you could just echo back <?php echo($gain-$spent);?> if you don’t need the $total figure elsewhere. Someone more proficient in php could doubtless write a more elegant version of this.

Viewing 1 replies (of 1 total)
  • The topic ‘Calculation in "add_post_meta"’ is closed to new replies.