Преглед изворни кода

:recycle: starting to return events by date

tags/0.9.0
j пре 4 година
родитељ
комит
756b5e1c66

+ 2
- 0
plugins/cia-endpoints/cia-end-points.php Прегледај датотеку

@@ -58,6 +58,8 @@ add_action( 'rest_api_init', function () {
58 58
     $sort_controller->register_custom_route('artists/by-alpha');
59 59
     $sort_controller = new Make_Sort_By('artist', 'by_material');
60 60
     $sort_controller->register_custom_route('artists/by-material');
61
+    $sort_controller = new Make_Sort_By('event', 'by_upcoming_event');
62
+    $sort_controller->register_custom_route('events/by-upcoming');
61 63
 });
62 64
 
63 65
 /**

+ 34
- 0
plugins/cia-endpoints/includes/class.make-sortby.php Прегледај датотеку

@@ -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();

+ 14
- 1
vue-theme/src/components/sidebars/exhibitions.vue Прегледај датотеку

@@ -13,4 +13,17 @@ ul.t-up
13 13
         p date from  -  date to
14 14
         p 
15 15
 
16
-</template>
16
+</template>
17
+
18
+<script>
19
+export default {
20
+    props: {
21
+        postsByType:{
22
+            required: true
23
+        }, 
24
+        postType:{
25
+            required: true
26
+        }, 
27
+    }
28
+}
29
+</script>

Loading…
Откажи
Сачувај