PluginProbe ʕ •ᴥ•ʔ
Post Views Counter / 1.0.3
Post Views Counter v1.0.3
1.7.13 1.7.12 1.7.11 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.2.0 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.2 1.3.2.1 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.7.0 1.7.1 1.7.10 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9
post-views-counter / includes / query.php
post-views-counter / includes Last commit date
columns.php 12 years ago counter.php 12 years ago cron.php 12 years ago frontend.php 11 years ago functions.php 12 years ago query.php 12 years ago settings.php 12 years ago update.php 12 years ago widgets.php 12 years ago
query.php
78 lines
1 <?php
2 if(!defined('ABSPATH')) exit;
3
4 new Post_Views_Counter_Query();
5
6 class Post_Views_Counter_Query
7 {
8 public function __construct()
9 {
10 // actions
11 add_action('pre_get_posts', array(&$this, 'extend_pre_query'), 9);
12
13 // filters
14 add_filter('posts_join', array(&$this, 'posts_join'), 10, 2);
15 add_filter('posts_groupby', array(&$this, 'posts_groupby'), 10, 2);
16 add_filter('posts_orderby', array(&$this, 'posts_orderby'), 10, 2);
17 }
18
19
20 /**
21 *
22 */
23 public function extend_pre_query($query)
24 {
25 // adds new parameter
26 if(isset($query->query_vars['orderby']) && $query->query_vars['orderby'] === 'post_views')
27 $query->order_by_post_views = true;
28 }
29
30
31 /**
32 *
33 */
34 public function posts_join($join, $query)
35 {
36 global $wpdb;
37
38 // is it sorted by post views?
39 if(isset($query->order_by_post_views) && $query->order_by_post_views)
40 $join .= " LEFT JOIN ".$wpdb->prefix."post_views pvc ON pvc.id = ".$wpdb->prefix."posts.ID AND pvc.type = 4";
41
42 return $join;
43 }
44
45
46 /**
47 *
48 */
49 public function posts_groupby($groupby, $query)
50 {
51 global $wpdb;
52
53 // is it sorted by post views?
54 if(isset($query->order_by_post_views) && $query->order_by_post_views)
55 $groupby = (trim($groupby) !== '' ? $groupby.', ' : '').$wpdb->prefix.'posts.ID';
56
57 return $groupby;
58 }
59
60
61 /**
62 *
63 */
64 public function posts_orderby($orderby, $query)
65 {
66 global $wpdb;
67
68 // is it sorted by post views?
69 if(isset($query->order_by_post_views) && $query->order_by_post_views)
70 {
71 $order = $query->get('order');
72 $orderby = 'pvc.count '.$order.', '.$wpdb->prefix.'posts.ID '.$order;
73 }
74
75 return $orderby;
76 }
77 }
78 ?>