Skip to content

Instantly share code, notes, and snippets.

@tollmanz
Created April 10, 2012 19:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tollmanz/2353754 to your computer and use it in GitHub Desktop.
Save tollmanz/2353754 to your computer and use it in GitHub Desktop.
Fix for messing up the global $post object on a write screen
<?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