Explorar el Código

:recycle: chopping excerpt lengths | episode sort working

tags/0.9.0
J hace 4 años
padre
commit
b53a7c2d66

+ 1
- 1
plugins/cia-endpoints/cia-end-points.php Ver fichero

@@ -87,5 +87,5 @@ add_filter('wp_rest_cache/allowed_endpoints', function () {
87 87
 }, 10, 1);
88 88
 
89 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 Ver fichero

@@ -56,11 +56,6 @@ class Make_Sort_By extends WP_REST_Controller {
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 60
         return $args;
66 61
     }
@@ -139,11 +134,25 @@ class Make_Sort_By extends WP_REST_Controller {
139 134
 
140 135
     public function by_episode( $request ) {
141 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 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 158
     public function prepare_items_for_reponse( $items ) {
@@ -152,7 +161,6 @@ class Make_Sort_By extends WP_REST_Controller {
152 161
         forEach( $items as $item ) {
153 162
             $formatted = default_post_format( $item, false );
154 163
             $formatted[hero] = get_post_meta( $item->ID, 'hero_header', true );
155
-            $formatted[relatedto] = p2p_related_to( $item->ID, false );
156 164
             array_push($collection, $formatted);
157 165
         }
158 166
 

+ 4
- 6
plugins/cia-endpoints/includes/formats.php Ver fichero

@@ -67,6 +67,10 @@ function default_post_format( $item, $include_content ) {
67 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 74
     return $filtered;
71 75
 }
72 76
 
@@ -91,12 +95,6 @@ function minimal_post_format( $item ) {
91 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 98
     return $filtered;
101 99
 }
102 100
 

Loading…
Cancelar
Guardar