Skip to content

Instantly share code, notes, and snippets.

@generatepress
Created September 26, 2014 17:36
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 generatepress/6c34867033af757b71b6 to your computer and use it in GitHub Desktop.
Save generatepress/6c34867033af757b71b6 to your computer and use it in GitHub Desktop.
/**
* Fix page template issue causing metaboxes not to save
*/
add_action('admin_init','generate_update_page_template_issue');
function generate_update_page_template_issue()
{
global $post;
$args = array(
'post_status' => 'publish',
'posts_per_page' => -1,
'post_type' => 'page'
);
$posts = get_posts($args);
foreach ( $posts as $post ) {
$page_template = $post->page_template;
if( !locate_template($page_template) ) :
update_post_meta($post->ID, '_wp_page_template', 'default');
endif;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment