Last active
November 5, 2022 11:31
-
-
Save maximilliangeorge/628773317455b7f81eedba60ddafd34e to your computer and use it in GitHub Desktop.
Fix memory leaks in wordpress admin
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 | |
/** | |
* 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