我試圖迴應自定義帖子類型中所有評分的平均值,但沒有達到此值。ACF中CPT的總和和平均值
編輯:總價值沒有顯示出來,所以我不能計算平均
我希望有人能幫助我。
$args = array('post_type' => 'ratings');
$ratings = new WP_Query($args);
$count = $ratings->post_count;
$total = 0;
$average = $total/$count;
while (have_rows('ratings')) : the_row();
$total += intval(the_field('rating_num'));
endwhile;
echo $average;
wp_reset_query();
嗨解決了!請詳細說明什麼是不工作/你得到什麼錯誤? – Epodax
嗨!總價值沒有顯示出來,所以我無法獲得平均值 – Falch0n
「評級」行中的字段'rating_nums'是否存在並且有可轉換爲整數的值? – Dilettant