function get_totalviews_term($term_id = 1, $display = true, $with_bot = true, $type = '') { global $wpdb; $where = ''; $inner_join = ''; if ($term_id != 0) { if (is_array($term_id)) { $term_id = array_map('intval', $term_id); $where = 'tt.term_id IN (' . implode(',', $term_id) . ') AND '; } else { $where = 'tt.term_id=' . intval($term_id) . ' AND '; } $inner_join = 'INNER JOIN ' . $wpdb->term_relationships . ' AS tr ON pm.post_id = tr.object_id' . ' INNER JOIN ' . $wpdb->term_taxonomy . ' AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id AND tt.taxonomy = "' . $type . '"'; } $add_word = get_totalviews_stats_word($term_id, $with_bot, $type); if ($with_bot) { $total_views = $wpdb->get_var('SELECT SUM(IFNULL(CAST(pm.meta_value AS UNSIGNED), 0)) FROM ' . $wpdb->postmeta . ' AS pm ' . $inner_join . ' WHERE ' . $where . ' (pm.meta_key = "' . WP_PVP::$post_meta_views . '" OR pm.meta_key = "' . WP_PVP::$post_meta_botviews . '")'); $template = str_replace('%VIEW_COUNT%', '<span id="wppvp_gt_' . $add_word . '">%VIEW_COUNT%</span>', WP_PVP::$options['template']); } else { $total_views = $wpdb->get_var('SELECT SUM(IFNULL(CAST(pm.meta_value AS UNSIGNED), 0)) FROM ' . $wpdb->postmeta . ' AS pm ' . $inner_join . ' WHERE ' . $where . ' pm.meta_key = "' . WP_PVP::$post_meta_views . '"'); $template = str_replace('%VIEW_COUNT%', '<span id="wppvp_gt_' . $add_word . '">%VIEW_COUNT%</span>', WP_PVP::$options['user_template']); } $total_views = intval($total_views); if ($display) { if (defined('WP_CACHE') && WP_CACHE) { WP_PVP::add_cache_stats('gt', $term_id, $with_bot, $type); $template = str_replace('%VIEW_COUNT%', '', $template); } else { $template = str_replace('%VIEW_COUNT%', number_format_i18n($total_views), $template); } echo $template; } else { return $total_views; } }