Created
June 9, 2016 23:14
-
-
Save spacedmonkey/6a9637f5765a0b39c3c3b01a9667ddc8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function pre_get_posts( $wp_query ) { | |
$this->cache_queries = apply_filters( 'use_enhanced_post_cache', true, $wp_query ); | |
if( $this->cache_queries ){ | |
if ( $wp_query->is_404() ) { | |
$page_variable = array( 'error_404' ); | |
} else { | |
$page_variable = $wp_query->query_vars; | |
} | |
$page_variable['paged'] = 0; | |
asort( $page_variable ); | |
$cache_key = md5( serialize( $page_variable ) ); | |
$cache = wp_cache_get( $cache_key . $this->cache_salt, $this->cache_group ); | |
if ( is_array( $cache ) ){ | |
$wp_query->queried_object = $cache['object']; | |
$wp_query->queried_object_id = $cache['object_id']; | |
} else{ | |
$value = array( | |
'object' => $wp_query->get_queried_object(), | |
'object_id' => $wp_query->get_queried_object_id() | |
); | |
wp_cache_add( $cache_key . $this->cache_salt, $value, $this->cache_group ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment