|
|
@@ -42,7 +42,7 @@ class Make_Sort_By extends WP_REST_Controller {
|
|
42
|
42
|
$res = $wpdb->get_results($wpdb->prepare(
|
|
43
|
43
|
"SELECT * FROM wp_posts
|
|
44
|
44
|
WHERE post_type = %s
|
|
45
|
|
- AND post_status='publish'",
|
|
|
45
|
+ AND post_status = 'publish'",
|
|
46
|
46
|
$this->post_type
|
|
47
|
47
|
));
|
|
48
|
48
|
wp_reset_postdata();
|
|
|
@@ -50,37 +50,64 @@ class Make_Sort_By extends WP_REST_Controller {
|
|
50
|
50
|
return new WP_REST_Response( $this->prepare_items_for_reponse($res), 200 );
|
|
51
|
51
|
}
|
|
52
|
52
|
|
|
53
|
|
- public function by_upcoming_event( $request ) {
|
|
|
53
|
+ public function by_past( $request ) {
|
|
54
|
54
|
global $wpdb;
|
|
55
|
|
- $time = new DateTime();
|
|
56
|
|
- $timestamp = $time->getTimestamp();
|
|
|
55
|
+ $time = strval(time());
|
|
|
56
|
+ $end = 'exhibit-end-date';
|
|
|
57
|
+ if($this->post_type == 'event') {
|
|
|
58
|
+ $end = 'event-end-time';
|
|
|
59
|
+ }
|
|
57
|
60
|
$res = $wpdb->get_results($wpdb->prepare(
|
|
58
|
|
- "SELECT DISTINCT wp_posts.*
|
|
59
|
|
- FROM wp_posts LEFT JOIN wp_postmeta AS ends
|
|
60
|
|
- ON (ends.post_id = wp_posts.ID AND ends.meta_key='event-end-time' AND ends.meta_value <= %d)
|
|
61
|
|
- WHERE post_type = %s
|
|
62
|
|
- AND CONVERT('event-end-time', DATETIME) >= CONVERT('2021-10-31', DATETIME)
|
|
63
|
|
- AND post_status='publish'
|
|
|
61
|
+ "SELECT DISTINCT wp_posts.* FROM wp_posts
|
|
|
62
|
+ JOIN wp_postmeta AS ends
|
|
|
63
|
+ ON (ends.post_id = wp_posts.ID AND ends.meta_key = %s AND ends.meta_value <= %s)
|
|
|
64
|
+ WHERE post_type = %s AND post_status = 'publish'
|
|
64
|
65
|
ORDER BY ends.meta_value DESC",
|
|
65
|
|
- $time, $this->post_type
|
|
|
66
|
+ $end, $time, $this->post_type
|
|
66
|
67
|
));
|
|
67
|
68
|
wp_reset_postdata();
|
|
|
69
|
+ return new WP_REST_Response( $this->prepare_items_for_reponse($res), 200 );
|
|
|
70
|
+ }
|
|
68
|
71
|
|
|
|
72
|
+ public function by_current( $request ) {
|
|
|
73
|
+ global $wpdb;
|
|
|
74
|
+ $time = strval(time());
|
|
|
75
|
+ $start = 'exhibit-start-date';
|
|
|
76
|
+ $end = 'exhibit-end-date';
|
|
|
77
|
+ if($this->post_type == 'event') {
|
|
|
78
|
+ $start = 'event-start-time';
|
|
|
79
|
+ $end = 'event-end-time';
|
|
|
80
|
+ }
|
|
|
81
|
+ $res = $wpdb->get_results($wpdb->prepare(
|
|
|
82
|
+ "SELECT DISTINCT wp_posts.* FROM wp_posts
|
|
|
83
|
+ JOIN wp_postmeta AS starts
|
|
|
84
|
+ ON (starts.post_id = wp_posts.ID AND starts.meta_key = %s AND starts.meta_value <= %s)
|
|
|
85
|
+ JOIN wp_postmeta AS ends
|
|
|
86
|
+ ON (ends.post_id = wp_posts.ID AND ends.meta_key = %s AND ends.meta_value >= %s)
|
|
|
87
|
+ WHERE post_type = %s AND post_status = 'publish'
|
|
|
88
|
+ ORDER BY starts.meta_value DESC",
|
|
|
89
|
+ $start, $time, $end, $time, $this->post_type
|
|
|
90
|
+ ));
|
|
|
91
|
+ wp_reset_postdata();
|
|
69
|
92
|
return new WP_REST_Response( $this->prepare_items_for_reponse($res), 200 );
|
|
70
|
93
|
}
|
|
71
|
|
- public function by_upcoming_exhibition( $request ) {
|
|
|
94
|
+
|
|
|
95
|
+ public function by_upcoming( $request ) {
|
|
72
|
96
|
global $wpdb;
|
|
|
97
|
+ $time = strval(time());
|
|
|
98
|
+ $start = 'exhibit-start-date';
|
|
|
99
|
+ if($this->post_type == 'event') {
|
|
|
100
|
+ $start = 'event-start-time';
|
|
|
101
|
+ }
|
|
73
|
102
|
$res = $wpdb->get_results($wpdb->prepare(
|
|
74
|
|
- "SELECT DISTINCT wp_posts.*
|
|
75
|
|
- FROM wp_posts LEFT JOIN wp_postmeta
|
|
76
|
|
- ON (wp_postmeta.post_id = wp_posts.ID AND wp_postmeta.meta_key='exhibit-end-date')
|
|
77
|
|
- WHERE post_type = 'exhibition'
|
|
78
|
|
- AND post_status='publish'
|
|
79
|
|
- ORDER BY 'exhibit-end-date'",
|
|
80
|
|
- $this->post_type
|
|
|
103
|
+ "SELECT DISTINCT wp_posts.* FROM wp_posts
|
|
|
104
|
+ JOIN wp_postmeta AS starts
|
|
|
105
|
+ ON (starts.post_id = wp_posts.ID AND starts.meta_key = %s AND starts.meta_value >= %s)
|
|
|
106
|
+ WHERE post_type = %s AND post_status = 'publish'
|
|
|
107
|
+ ORDER BY starts.meta_value DESC",
|
|
|
108
|
+ $start, $time, $this->post_type
|
|
81
|
109
|
));
|
|
82
|
110
|
wp_reset_postdata();
|
|
83
|
|
-
|
|
84
|
111
|
return new WP_REST_Response( $this->prepare_items_for_reponse($res), 200 );
|
|
85
|
112
|
}
|
|
86
|
113
|
|