Skip to content

Instantly share code, notes, and snippets.

@mattwiebe
Created September 9, 2010 03:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mattwiebe/571328 to your computer and use it in GitHub Desktop.
Save mattwiebe/571328 to your computer and use it in GitHub Desktop.
<?php
/**
* A couple of functions for caching the global post object so that contextual
* stuff (eg: sidebars) still works after custom queries
* NOT for use with query_posts(). Real WP coders always do a new WP_Query.
*/
function sd_cache_post() {
global $post, $sd_cached_post;
$sd_cached_post = $post;
}
function sd_revert_post() {
global $post, $sd_cached_post;
if ( is_object($sd_cached_post) && isset($sd_cached_post->ID) && $sd_cached_post->ID !== $post->ID ) {
$post = $sd_cached_post;
setup_postdata($post);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment