Bladeren bron

:recycle: chopping excerpt lengths | episode sort working

tags/0.9.0
J 4 jaren geleden
bovenliggende
commit
b53a7c2d66

+ 1
- 1
plugins/cia-endpoints/cia-end-points.php Bestand weergeven

87
 }, 10, 1);
87
 }, 10, 1);
88
 
88
 
89
 add_filter('excerpt_length', function ($length) {
89
 add_filter('excerpt_length', function ($length) {
90
-    return 60;
90
+    return 30;
91
 });
91
 });

+ 17
- 9
plugins/cia-endpoints/includes/class.make-sortby.php Bestand weergeven

56
                 ]
56
                 ]
57
             );
57
             );
58
         }
58
         }
59
-        
60
-        if($params['episode']) {
61
-            $args['p2p_query'] = $params['episode'];
62
-            $args['tax_query'] = [];
63
-        }
64
 
59
 
65
         return $args;
60
         return $args;
66
     }
61
     }
139
 
134
 
140
     public function by_episode( $request ) {
135
     public function by_episode( $request ) {
141
         $q = new WP_Query($this->make_args($request, null));
136
         $q = new WP_Query($this->make_args($request, null));
142
-        $episode_name = $q->query->p2p_query;
143
-        $items = $this->prepare_items_for_reponse($q->get_posts());
137
+        global $wpdb;
138
+        $type = $q->query['post_type'] . 's';
139
+        // TODO: optimize this query
140
+        // $items = $q->get_posts();
141
+        $items = $wpdb->get_results($wpdb->prepare(
142
+            "SELECT DISTINCT wp_posts.*, 
143
+                header.post_title AS related_episode 
144
+            FROM wp_posts LEFT JOIN wp_p2p 
145
+            ON (wp_p2p.p2p_from = wp_posts.ID OR wp_p2p.p2p_to = wp_posts.ID) 
146
+            LEFT JOIN wp_posts AS header 
147
+            ON header.ID = IF(wp_posts.ID = wp_p2p.p2p_to, wp_p2p.p2p_from, wp_p2p.p2p_to) 
148
+            WHERE wp_posts.post_type = %s AND wp_posts.post_status = 'publish' 
149
+                AND (wp_p2p.p2p_type = %s OR wp_p2p.p2p_type = %s) 
150
+            ORDER BY header.post_date DESC, related_episode, wp_posts.post_date DESC",
151
+            trim($type, 's'), $type . "_to_episodes" , "episodes_to_" . $type,
152
+        ));
144
         wp_reset_postdata();
153
         wp_reset_postdata();
145
 
154
 
146
-        return new WP_REST_Response( $items, 200 );
155
+        return new WP_REST_Response( $this->prepare_items_for_reponse($items), 200 );
147
     }
156
     }
148
 
157
 
149
     public function prepare_items_for_reponse( $items ) {
158
     public function prepare_items_for_reponse( $items ) {
152
         forEach( $items as $item ) {
161
         forEach( $items as $item ) {
153
             $formatted = default_post_format( $item, false );
162
             $formatted = default_post_format( $item, false );
154
             $formatted[hero] = get_post_meta( $item->ID, 'hero_header', true );
163
             $formatted[hero] = get_post_meta( $item->ID, 'hero_header', true );
155
-            $formatted[relatedto] = p2p_related_to( $item->ID, false );
156
             array_push($collection, $formatted);
164
             array_push($collection, $formatted);
157
         }
165
         }
158
 
166
 

+ 4
- 6
plugins/cia-endpoints/includes/formats.php Bestand weergeven

67
         $filtered[tags] = make_taxonomy_endpoint_for(get_the_terms( $item, 'post_tag' ));
67
         $filtered[tags] = make_taxonomy_endpoint_for(get_the_terms( $item, 'post_tag' ));
68
     }
68
     }
69
 
69
 
70
+    if($item->related_episode) {
71
+        $filtered[related_episode] = strtolower($item->related_episode);
72
+    }
73
+
70
     return $filtered;
74
     return $filtered;
71
 }
75
 }
72
 
76
 
91
         $filtered[current] = time() <= (int)$filtered[end] && time() >= (int)$filtered[start];
95
         $filtered[current] = time() <= (int)$filtered[end] && time() >= (int)$filtered[start];
92
     }
96
     }
93
 
97
 
94
-    // Post categories and tags (store just the slugs)
95
-    if($item->post_type === 'post') {
96
-        $filtered[categories] = make_taxonomy_endpoint_for(get_the_terms( $item, 'category' ));
97
-        $filtered[tags] = make_taxonomy_endpoint_for(get_the_terms( $item, 'post_tag' ));
98
-    }
99
-
100
     return $filtered;
98
     return $filtered;
101
 }
99
 }
102
 
100
 

Laden…
Annuleren
Opslaan