<?php
$args = array(
'orderby' => 'name',
'parent' => 0,
'depth' => 0
);
$categories = get_categories( $args );
foreach ( $categories as $category ) {
$cat_id = $category->term_id;
$args_post = array(
'cat' => $cat_id,
'post_type' => 'post',
'posts_per_page' => '-1',
);
$query = new WP_Query( $args_post );
$allview = array();
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
$post_id = get_the_ID();
if ( !isset( $allview[$cat_id] ) {
$allview[$cat_id] = 0;
}
$post_views_count = get_post_meta( $post_id, 'post_views_count' );
$allview[$cat_id] = (int)$allview[$cat_id] + (int)$post_views_count;
}
}
}
//display results
foreach ( $allview as $cat => $value ) {
echo $cat . ' = ' . $value;
}
?>