Created
July 13, 2012 11:35
-
-
Save trovster/3104443 to your computer and use it in GitHub Desktop.
Latest Posts
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
| <?php | |
| /** | |
| * template_pre_loop | |
| * @desc Used before a custom loop | |
| * Parameter is the WP_Query options for the new loop | |
| * Saves the original query and post data | |
| * Returns the new query, along with the original wp_query and post | |
| * @param array $options | |
| * @return array | |
| */ | |
| function template_pre_loop($options) { | |
| global $wp_query, $post; | |
| $original_post = null; | |
| $original_wp_query = null; | |
| if(!empty($post)) { | |
| $original_post = clone $post; | |
| } | |
| if(!empty($wp_query)) { | |
| $original_wp_query = clone $wp_query; | |
| } | |
| $wp_query = new WP_Query($options); | |
| return compact('wp_query', 'original_wp_query', 'original_post'); | |
| } | |
| /** | |
| * template_post_loop | |
| * @desc Used after a custom loop | |
| * Parameter is the original array saved from the pre loop function | |
| * Resets the query and post data | |
| * Returns the original wp_query and post data | |
| * @param array $original | |
| * @return array | |
| */ | |
| function template_post_loop($original) { | |
| global $wp_query, $post; | |
| extract($original); | |
| if(!empty($original_wp_query)) { | |
| $wp_query = clone $original_wp_query; | |
| } | |
| if(!empty($original_post)) { | |
| $post = clone $original_post; | |
| } | |
| wp_reset_query(); | |
| return compact('wp_query', 'post'); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment