|
|
@@ -49,6 +49,40 @@ class Make_Sort_By extends WP_REST_Controller {
|
|
49
|
49
|
|
|
50
|
50
|
return new WP_REST_Response( $this->prepare_items_for_reponse($res), 200 );
|
|
51
|
51
|
}
|
|
|
52
|
+
|
|
|
53
|
+ public function by_upcoming_event( $request ) {
|
|
|
54
|
+ global $wpdb;
|
|
|
55
|
+ $time = new DateTime();
|
|
|
56
|
+ $timestamp = $time->getTimestamp();
|
|
|
57
|
+ $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'
|
|
|
64
|
+ ORDER BY ends.meta_value DESC",
|
|
|
65
|
+ $time, $this->post_type
|
|
|
66
|
+ ));
|
|
|
67
|
+ wp_reset_postdata();
|
|
|
68
|
+
|
|
|
69
|
+ return new WP_REST_Response( $this->prepare_items_for_reponse($res), 200 );
|
|
|
70
|
+ }
|
|
|
71
|
+ public function by_upcoming_exhibition( $request ) {
|
|
|
72
|
+ global $wpdb;
|
|
|
73
|
+ $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
|
|
|
81
|
+ ));
|
|
|
82
|
+ wp_reset_postdata();
|
|
|
83
|
+
|
|
|
84
|
+ return new WP_REST_Response( $this->prepare_items_for_reponse($res), 200 );
|
|
|
85
|
+ }
|
|
52
|
86
|
|
|
53
|
87
|
public function prepare_items_for_reponse( $items ) {
|
|
54
|
88
|
$collection = array();
|