Skip to content

Instantly share code, notes, and snippets.

@maximilliangeorge
Last active November 5, 2022 11:31
Show Gist options
  • Save maximilliangeorge/628773317455b7f81eedba60ddafd34e to your computer and use it in GitHub Desktop.
Save maximilliangeorge/628773317455b7f81eedba60ddafd34e to your computer and use it in GitHub Desktop.
Fix memory leaks in wordpress admin
<?php
/**
* Disable Posts' meta from being preloaded
* This fixes memory problems in the WordPress Admin
*/
function jb_pre_get_posts( WP_Query $wp_query ) {
if ( in_array( $wp_query->get( 'post_type' ), array( 'my_post_type_1', 'my_post_type_2' ) ) ) {
$wp_query->set( 'update_post_meta_cache', false );
}
}
// Only do this for admin
if ( is_admin() ) {
add_action( 'pre_get_posts', 'jb_pre_get_posts' );
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment