感谢@prosti的回答,我根据你的回答编写了这个小代码,它对我有用
global $post;
$query_args = array(
\'post_type\' => \'post\',
\'post_status\' => \'publish\',
\'order\' => \'DESC\',
\'posts_per_page\' => -1,
\'cat\' => 1,
// \'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(),\'download_counter\' ));
}
}
echo $sum ;