Tell us what you are trying to do?
I have up to 6 scoring questions each with a possible score of up to 10 - chosen by select field. I would like to add these scores to store a total score.
Is there a similar example that we can see?
I have tried using this but it just returns 0
function calculate_fields( $post_ID ) {
if ( get_post_type( $post_ID ) == 'application1' ) {
$totalscore = $score1 + $score2 + $score3 + $score4 + $score5 + $score6;
$score1 = get_post_meta($post_ID, 'wpcf-assessment-criteria-score-1',true);
$score2 = get_post_meta($post_ID, 'wpcf-assessment-criteria-score-2',true);
$score3 = get_post_meta($post_ID, 'wpcf-assessment-criteria-score-3',true);
$score4 = get_post_meta($post_ID, 'wpcf-assessment-criteria-score-4',true);
$score5 = get_post_meta($post_ID, 'wpcf-assessment-criteria-score-5',true);
$score6 = get_post_meta($post_ID, 'wpcf-assessment-criteria-score-6',true);
update_post_meta( $post_ID, 'wpcf-cja-longlist-score', $totalscore );
}
}
add_action( 'save_post', 'calculate_fields', 99 );
add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data) {
// if a specific form
if ($form_data['id']==561) {
calculate_fields( $post_id );
}