Przeglądaj źródła

:bug: tweaking sql query for by-episode sort

tags/0.9.0
J 4 lat temu
rodzic
commit
8744b4aa34

+ 4
- 3
plugins/cia-endpoints/includes/class.make-sortby.php Wyświetl plik

156
     public function by_episode( $request ) {
156
     public function by_episode( $request ) {
157
         $q = new WP_Query($this->make_args($request, null));
157
         $q = new WP_Query($this->make_args($request, null));
158
         global $wpdb;
158
         global $wpdb;
159
+        
159
         $type = $q->query['post_type'] . 's';
160
         $type = $q->query['post_type'] . 's';
161
+        
160
         // TODO: optimize this query
162
         // TODO: optimize this query
161
-        // $items = $q->get_posts();
162
         $items = $wpdb->get_results($wpdb->prepare(
163
         $items = $wpdb->get_results($wpdb->prepare(
163
             "SELECT DISTINCT wp_posts.*, 
164
             "SELECT DISTINCT wp_posts.*, 
164
                 header.post_title AS related_episode 
165
                 header.post_title AS related_episode 
166
             ON (wp_p2p.p2p_from = wp_posts.ID OR wp_p2p.p2p_to = wp_posts.ID) 
167
             ON (wp_p2p.p2p_from = wp_posts.ID OR wp_p2p.p2p_to = wp_posts.ID) 
167
             LEFT JOIN wp_posts AS header 
168
             LEFT JOIN wp_posts AS header 
168
             ON header.ID = IF(wp_posts.ID = wp_p2p.p2p_to, wp_p2p.p2p_from, wp_p2p.p2p_to) 
169
             ON header.ID = IF(wp_posts.ID = wp_p2p.p2p_to, wp_p2p.p2p_from, wp_p2p.p2p_to) 
169
-            WHERE wp_posts.post_type = %s AND wp_posts.post_status = 'publish' 
170
+            WHERE wp_posts.post_status = 'publish' 
170
                 AND (wp_p2p.p2p_type = %s OR wp_p2p.p2p_type = %s) 
171
                 AND (wp_p2p.p2p_type = %s OR wp_p2p.p2p_type = %s) 
171
             ORDER BY header.post_date DESC, related_episode, wp_posts.post_date DESC",
172
             ORDER BY header.post_date DESC, related_episode, wp_posts.post_date DESC",
172
-            trim($type, 's'), $type . "_to_episodes" , "episodes_to_" . $type,
173
+            trim($type, 's'), $type . '_to_episodes' , 'episodes_to_' . $type,
173
         ));
174
         ));
174
         wp_reset_postdata();
175
         wp_reset_postdata();
175
 
176
 

+ 13
- 9
vue-theme/src/store/modules/arrangements.js Wyświetl plik

1
 import { sortTypes } from '../../utils/helpers'
1
 import { sortTypes } from '../../utils/helpers'
2
 
2
 
3
-const _makeFlatpack = bySort => {
4
-    const flatPacked = []
5
-    Object.keys(bySort).forEach(sort => {
6
-        flatPacked.push({ slug: sort, title: sort, inbetween: true })
7
-        bySort[sort].forEach(post => flatPacked.push(post))
3
+const _insertInBetweens = bySort => {
4
+    const postListWithInBetweens = []
5
+    Object.keys(bySort).forEach(term => {
6
+        postListWithInBetweens.push({ 
7
+            slug: term,
8
+            title: term,
9
+            inbetween: true
10
+        })
11
+        bySort[term].forEach(post => postListWithInBetweens.push(post))
8
     })
12
     })
9
-    return flatPacked
13
+    return postListWithInBetweens
10
 }
14
 }
11
 
15
 
12
 const _arrangeByMaterial = postsList => {
16
 const _arrangeByMaterial = postsList => {
19
             byMaterial[mat].push(post)
23
             byMaterial[mat].push(post)
20
         })
24
         })
21
     })
25
     })
22
-    const flatPacked = _makeFlatpack(byMaterial)
26
+    const flatPacked = _insertInBetweens(byMaterial)
23
     return flatPacked
27
     return flatPacked
24
 }
28
 }
25
 
29
 
32
             byType[type].push(post)
36
             byType[type].push(post)
33
         })
37
         })
34
     })
38
     })
35
-    const flatPacked = _makeFlatpack(byType)
39
+    const flatPacked = _insertInBetweens(byType)
36
     return flatPacked
40
     return flatPacked
37
 }
41
 }
38
 
42
 
65
         if(!byEpisode[relatedEpisode]) byEpisode[relatedEpisode] = []
69
         if(!byEpisode[relatedEpisode]) byEpisode[relatedEpisode] = []
66
         byEpisode[relatedEpisode].push(post)
70
         byEpisode[relatedEpisode].push(post)
67
     })
71
     })
68
-    const flatPacked = _makeFlatpack(byEpisode)
72
+    const flatPacked = _insertInBetweens(byEpisode)
69
     return flatPacked
73
     return flatPacked
70
 }
74
 }
71
 
75
 

Ładowanie…
Anuluj
Zapisz