% of total views
-
Is it right? Or is there a better, shorter, smarter way?
<?php $meta_key = 'views'; $all_views=$wpdb->get_var($wpdb->prepare("SELECT sum(meta_value) FROM $wpdb->postmeta WHERE meta_key = %s", $meta_key)); $sum = $all_views; $post_views = intval( get_post_meta( get_the_ID(), 'views', true ) ); echo round(($post_views * 100/$sum),2). " % of all views"; ?>
Example: https://kafka-literatur.de/bibliographie/1982/04336-horak-glebocki-kafkas-prag-heute (Footer)
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘% of total views’ is closed to new replies.