1

I have a custom post type named 'ordered_food' and the custom field named 'price', Alhough I can print out all the values, I don't know how to plus and calculate the total price. Because it's already in the wordpress custom post type loop.

Calculate all custom field values in the post loop

/* something like this */
$total_amount = $price_custom_field1 + $price_custom_field2 + $price_custom_field3; 
1

Try this:

//loop start

    $total_amount = get_post_meta($post->ID, 'custom_field1', true);
    $total_amount += get_post_meta($post->ID, 'custom_field2', true);
    $total_amount += get_post_meta($post->ID, 'custom_field3', true);

//loop end  

    echo 'Total: '.$total_amount;   
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.