您可以尝试以下操作来获取自定义值:
$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 );
然后计算平均值:
// 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! ";
}