-1, 'post_status' => 'publish' ); if ( isset($_POST['tag_id']) ) : $args['tax_query'] = array(array( 'taxonomy' => 'region', 'field' => 'id', 'terms' => $_POST['tax_id'], )); endif; //echo '
' . print_r($args, true) . '
'; $the_query = new WP_Query($args); while ( $the_query->have_posts() ) : $the_query->the_post(); $reg = get_post_meta(get_the_ID(), 'reg_count'); $unreg = get_post_meta(get_the_ID(), 'unreg_count'); $reg_count = $reg_count + $reg[0]; $unreg_count = $unreg_count + $unreg[0]; endwhile; echo "total: " . number_format($reg_count + $unreg_count); die(); } /** * non ajax return */ function get_views_nojax($tax_id = false) { $args = array( 'numberposts' => -1, 'post_status' => 'publish' ); if ( isset($tax_id) ) : $args['tax_query'] = array( array( 'taxonomy' => 'region', 'field' => 'id', 'terms' => $tax_id ); endif; $posts = get_posts( $args ); foreach ( $posts as $post ) : $reg = get_post_meta($post->ID, 'reg_count'); $unreg = get_post_meta($post->ID, 'unreg_count'); $reg_count = $reg_count + $reg[0]; $unreg_count = $unreg_count + $unreg[0]; endforeach; return "total " . number_format($reg_count + $unreg_count); } /** * the regions */ function list_regions() { // regions $args = array( 'orderby' => 'name', 'order' => 'ASC', 'taxonomy' => 'region', 'child_of' => 0 ); $cats = get_categories($args); foreach ( $cats as $cat ) : echo ''; echo '' . $cat->cat_ID . " " . $cat->name . ''; echo '' . $this->get_views_nojax($cat->cat_ID) . ''; echo 'Count Views'; echo ''; endforeach; } /** * Create the viewable page */ function jttvvs_settings_page() { ?>

Film View Stats

list_regions(); ?>
Total Views: get_views_nojax($cat->cat_ID); ?> Count Views
 
/* the jquery - in a separate file - loaded through function jttvvs_js() */ jQuery(document).ready( function($) { $("a.getviews").click( function() { var td = $(this).parent(); /* only fetch results once */ $(this).unbind('click').bind('click', function(){return false;}); // replace button with loader $(td).html(''); $.post($(this), { action: "get_views", tax_id: td.attr("id") }, function(data) { td.html(data); } ); return false; }); });