Is it possible to count the amount of the same meta_keys for the same post_id.
I have a page with the post_id 44 and every time a user submits something on this page a new database rule is added with the meta_key "post_rating_0".
There are over 30 rules now for this page and I want to count them. For other pages the same thing.
Is this possible?
Code so far:
global $post;
$query_args = array(
'post_type' => 'page',
'post_status' => 'publish',
'posts_per_page' => -1,
'meta_key' => 'post_rating_0'
// 'fields' => 'SUM(amount_to_paid)',
);
$sum = 0;
$query = new WP_Query($query_args);
if ( $query->have_posts() ) {
while( $query->have_posts() ) {
$query->the_post();
// do the processing for each post
$sum = $sum + intval(get_post_meta(get_the_id(),'post_rating_0', true ));
}
}
echo $sum ;
This is what I got so far... But what this does is echo the value of "2" what is very logic. It searches for posts with the meta_key "post_rating_0", counts them and that are 2 posts.
What I'm trying to do is count the amount of meta_keys "post_rating_0" are in one page.