Created
April 10, 2012 19:13
-
-
Save tollmanz/2353754 to your computer and use it in GitHub Desktop.
Fix for messing up the global $post object on a write screen
This file contains 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 | |
function meta_box_callback( $post_local ) { | |
global $post; | |
$post_global_copy = $post; | |
$my_query = new WP_Query( array( | |
'posts_per_page' => 10 | |
) ); | |
if ( $my_query->have_posts() ) { | |
while ( $my_query->have_posts() ) { | |
$my_query->the_post(); // This causes the global $post object to change | |
} | |
} | |
$post = $post_global_copy; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment