SUM items from Array?
-
I’m trying to add up all the comment meta for a particular meta key for a particular post. I feel like I’m close, but for some reason my output is always either ‘ArrayArrayArrayArrayArray’ or 1010101010, but I can never seem to get all those 10’s to add up. Here is what I have currently:
<?php $postid = get_the_ID(); // get id of current post $args = array( 'post_id' => $postid, 'count' => false, 'meta_key' => 'price', 'meta_value' => '', 'meta_query' => '' ); // The Query $comments_query = new WP_Comment_Query; $comments = $comments_query->query( $args ); // Comment Loop if ( $comments ) { foreach ($comments as $comment) { $rating = array($comment->meta_value); echo array_sum($rating);} } else { echo 'no price rating to calculate'; } ?>
>How do I get the $rating to be the added total of all the $comment->meta_value
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘SUM items from Array?’ is closed to new replies.