php - Calculate multiples $var on get_post_meta -
i'm new php , appreciate help. i'm trying understand why $skill not working on get_post_meta on wordpress.
i'm trying calculate (sum) meta fields numbers in each meta fields = 'ecpt_editorial', 'ecpt_branding', etc. (i.e. = 'ecpt_editoral' has 3 points in 1 post + 4 points in one.) i'm trying calculate them without need create $ each of them (they're many).
my errors: warning: illegal offset type in isset or empty in fatal error: unsupported operand types in
<?php $args = array( 'numberposts' => -1, 'post_type' => 'post',); $points = get_posts( $args ); $total = 0; $skill = array ('ecpt_editorial','ecpt_branding', 'ecpt_packaging'); foreach( $points $point ) { $single = get_post_meta( $point->id, $skill, false ); $total += $single;} echo $total; ++$total; ?>
you cant pass in array $key field. prob looking for:
$args = array( 'numberposts' => -1, 'post_type' => 'post',); $points = get_posts( $args ); $total = 0; $skill = array ('ecpt_editorial','ecpt_branding', 'ecpt_packaging'); foreach( $points $point ) { foreach($skill $key){ $single = get_post_meta( $point->id, $key, false ); var_dump($single); echo '<br>'; ${$key} += (int) $single; } } foreach($skill $key){ echo $key.'='.${$key}; // there 3 variables count values set, $ecpt_editorial , $ecpt_branding, $ecpt_packaging }
assuming not looking save $single use?
php arrays wordpress meta-boxes
No comments:
Post a Comment