4 added 79 characters in body
source | link

You can try this to fetch the custom values:

$c1 = get_post_meta( get_the_ID(), 'custom1', TRUE );   
$c2 = get_post_meta( get_the_ID(), 'custom2', TRUE );   
$c3 = get_post_meta( get_the_ID(), 'custom3', TRUE );   
$c4 = get_post_meta( get_the_ID(), 'custom4', TRUE );   

Then to calculate the average:

// check if c1, c2, c3 and c4 are all set:
if( strlen($c1) * strlen($c2) * strlen($c3) * strlen($c4) > 0 ){

    // convert the values from string to int/float:
    $c1 = 1 * $c1;
    $c2 = 1 * $c2;
    $c3 = 1 * $c3;
    $c4 = 1 * $c4;

    // calculate the average:
    $avg = ($c1 + $c2 + $c3 + $c4) / 4 ;

    // output:
    // var_dump($avg);
    printf( "The average is %.2f", $avg );    // with two decimals:


}else{
    echo " missing value! ";
}

You can try this to fetch the custom values:

$c1 = get_post_meta( get_the_ID(), 'custom1', TRUE );   
$c2 = get_post_meta( get_the_ID(), 'custom2', TRUE );   
$c3 = get_post_meta( get_the_ID(), 'custom3', TRUE );   
$c4 = get_post_meta( get_the_ID(), 'custom4', TRUE );   

Then to calculate the average:

// check if c1, c2, c3 and c4 are all set:
if( strlen($c1) * strlen($c2) * strlen($c3) * strlen($c4) > 0 ){

    // convert the values from string to int/float:
    $c1 = 1 * $c1;
    $c2 = 1 * $c2;
    $c3 = 1 * $c3;
    $c4 = 1 * $c4;

    // calculate the average:
    $avg = ($c1 + $c2 + $c3 + $c4) / 4 ;

    // output:
    var_dump($avg);

}else{
    echo " missing value! ";
}

You can try this to fetch the custom values:

$c1 = get_post_meta( get_the_ID(), 'custom1', TRUE );   
$c2 = get_post_meta( get_the_ID(), 'custom2', TRUE );   
$c3 = get_post_meta( get_the_ID(), 'custom3', TRUE );   
$c4 = get_post_meta( get_the_ID(), 'custom4', TRUE );   

Then to calculate the average:

// check if c1, c2, c3 and c4 are all set:
if( strlen($c1) * strlen($c2) * strlen($c3) * strlen($c4) > 0 ){

    // convert the values from string to int/float:
    $c1 = 1 * $c1;
    $c2 = 1 * $c2;
    $c3 = 1 * $c3;
    $c4 = 1 * $c4;

    // calculate the average:
    $avg = ($c1 + $c2 + $c3 + $c4) / 4 ;

    // output:
    // var_dump($avg);
    printf( "The average is %.2f", $avg );    // with two decimals:


}else{
    echo " missing value! ";
}
3 added 112 characters in body
source | link

You can try this to fetch the custom values:

$c1 = get_post_meta( get_the_ID(), 'custom1', TRUE );   
$c2 = get_post_meta( get_the_ID(), 'custom2', TRUE );   
$c3 = get_post_meta( get_the_ID(), 'custom3', TRUE );   
$c4 = get_post_meta( get_the_ID(), 'custom4', TRUE );   

Then to calculate the average:

// check if c1, c2, c3 and c4 are all set:
if( strlen($c1) * strlen($c2) * strlen($c3) * strlen($c4) > 0 ){

    // convert the values from string to int/float:
    $c1 = 1 * $c1;
    $c2 = 1 * $c2;
    $c3 = 1 * $c3;
    $c4 = 1 * $c4;

    // calculate the average:
    $avg = ($c1 + $c2 + $c3 + $c4) / 4 ;

    // output:
    var_dump($avg);

}else{
    echo " missing value! ";
}

You can try this:

$c1 = get_post_meta( get_the_ID(), 'custom1', TRUE );   
$c2 = get_post_meta( get_the_ID(), 'custom2', TRUE );   
$c3 = get_post_meta( get_the_ID(), 'custom3', TRUE );   
$c4 = get_post_meta( get_the_ID(), 'custom4', TRUE );   

Then to calculate the average:

// check if c1, c2, c3 and c4 are set:
if( strlen($c1) * strlen($c2) * strlen($c3) * strlen($c4) > 0 ){

    // convert the values from string to int/float:
    $c1 = 1 * $c1;
    $c2 = 1 * $c2;
    $c3 = 1 * $c3;
    $c4 = 1 * $c4;

    // calculate the average:
    $avg = ($c1 + $c2 + $c3 + $c4) / 4 ;

    // output:
    var_dump($avg);

}else{
    echo " missing value! ";
}

You can try this to fetch the custom values:

$c1 = get_post_meta( get_the_ID(), 'custom1', TRUE );   
$c2 = get_post_meta( get_the_ID(), 'custom2', TRUE );   
$c3 = get_post_meta( get_the_ID(), 'custom3', TRUE );   
$c4 = get_post_meta( get_the_ID(), 'custom4', TRUE );   

Then to calculate the average:

// check if c1, c2, c3 and c4 are all set:
if( strlen($c1) * strlen($c2) * strlen($c3) * strlen($c4) > 0 ){

    // convert the values from string to int/float:
    $c1 = 1 * $c1;
    $c2 = 1 * $c2;
    $c3 = 1 * $c3;
    $c4 = 1 * $c4;

    // calculate the average:
    $avg = ($c1 + $c2 + $c3 + $c4) / 4 ;

    // output:
    var_dump($avg);

}else{
    echo " missing value! ";
}
2 added 112 characters in body
source | link

You can try this:

$c1 = get_post_meta( get_the_ID(), 'custom1', TRUE );   
$c2 = get_post_meta( get_the_ID(), 'custom2', TRUE );   
$c3 = get_post_meta( get_the_ID(), 'custom3', TRUE );   
$c4 = get_post_meta( get_the_ID(), 'custom4', TRUE );   

Then to calculate the average:

// check if c1, c2, c3 and c4 are set:
if( strlen($c1) * strlen($c2) * strlen($c3) * strlen($c4) > 0 ){

    // convert the values from string to int/float:
    $c1 = 1 * $c1;
    $c2 = 1 * $c2;
    $c3 = 1 * $c3;
    $c4 = 1 * $c4;

    // calculate the average:
    $avg = ($c1 + $c2 + $c3 + $c4) / 4 ; 

    // output:
    var_dump($avg);

}else{
    echo " missing value! ";
}

You can try this:

$c1 = get_post_meta( get_the_ID(), 'custom1', TRUE );   
$c2 = get_post_meta( get_the_ID(), 'custom2', TRUE );   
$c3 = get_post_meta( get_the_ID(), 'custom3', TRUE );   
$c4 = get_post_meta( get_the_ID(), 'custom4', TRUE );   

Then to calculate the average:

// check if c1, c2, c3 and c4 are set:
if( strlen($c1) * strlen($c2) * strlen($c3) * strlen($c4) > 0 ){

    $c1 = 1 * $c1;
    $c2 = 1 * $c2;
    $c3 = 1 * $c3;
    $c4 = 1 * $c4;

    $avg = ($c1 + $c2 + $c3 + $c4) / 4 ;

    var_dump($avg);

}else{
    echo " missing value! ";
}

You can try this:

$c1 = get_post_meta( get_the_ID(), 'custom1', TRUE );   
$c2 = get_post_meta( get_the_ID(), 'custom2', TRUE );   
$c3 = get_post_meta( get_the_ID(), 'custom3', TRUE );   
$c4 = get_post_meta( get_the_ID(), 'custom4', TRUE );   

Then to calculate the average:

// check if c1, c2, c3 and c4 are set:
if( strlen($c1) * strlen($c2) * strlen($c3) * strlen($c4) > 0 ){

    // convert the values from string to int/float:
    $c1 = 1 * $c1;
    $c2 = 1 * $c2;
    $c3 = 1 * $c3;
    $c4 = 1 * $c4;

    // calculate the average:
    $avg = ($c1 + $c2 + $c3 + $c4) / 4 ; 

    // output:
    var_dump($avg);

}else{
    echo " missing value! ";
}
1
source | link