File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -163,3 +163,43 @@ function add_custom_query_params( $args, $request ) {
163
163
164
164
return $ merged ;
165
165
}
166
+
167
+
168
+
169
+ /**
170
+ * Retrieve any cached AQL instances and bypass making a query.
171
+ */
172
+ add_filter (
173
+ 'posts_pre_query ' ,
174
+ function ( $ null_return , $ query ) {
175
+ if ( isset ( $ query ->query ['is_aql ' ] ) ) {
176
+ $ cached_query = get_transient ( $ query ->query_vars_hash );
177
+ if ( $ cached_query ) {
178
+ $ query ->found_posts = $ cached_query ->found_posts ;
179
+ $ query ->max_num_pages = $ cached_query ->max_num_pages ;
180
+ return $ cached_query ->posts ;
181
+ }
182
+ return $ null_return ;
183
+ }
184
+ return $ null_return ;
185
+ },
186
+ 10 ,
187
+ 2
188
+ );
189
+
190
+ /**
191
+ * Create a cache for the Query generated by the AQL instance.
192
+ */
193
+ add_filter (
194
+ 'the_posts ' ,
195
+ function ( $ posts , $ query ) {
196
+ if ( isset ( $ query ->query ['is_aql ' ] ) ) {
197
+ if ( ! get_transient ( $ query ->query_vars_hash ) ) {
198
+ set_transient ( $ query ->query_vars_hash , $ query , HOUR_IN_SECONDS );
199
+ }
200
+ }
201
+ return $ posts ;
202
+ },
203
+ 10 ,
204
+ 2
205
+ );
You can’t perform that action at this time.
0 commit comments