Created
March 4, 2019 12:24
-
-
Save n7studios/33f7b1ed9f21226133de71d3c993808d to your computer and use it in GitHub Desktop.
Custom Fields Meta Box: Define Meta Keys for Performance
This file contains hidden or 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 | |
/** | |
* Plugin Name: Custom Fields Meta Box: Define Meta Keys for Performance | |
* Plugin URI: http://www.wpzinc.com/ | |
* Version: 0.0.1 | |
* Author: WP Zinc | |
* Author URI: http://www.wpzinc.com | |
* Description: Explicitly define the Meta Keys to display in the Custom Fields > Add New Custom Field > Name <select> dropdown, to save WordPress performing a potentially expensive and slow query. | |
*/ | |
/** | |
* Defines the Meta Keys to display in the <select> dropdown. | |
* | |
* If null is returned, WordPress will perform a DB query to fetch all unique | |
* meta keys from the Post Meta table, which can be a slow and expensive | |
* query if the WordPress installations contains a lot of post meta data. | |
* | |
* @since 0.0.1 | |
* | |
* @param array $meta_keys Meta Keys | |
* @param WP_Post $post WordPress Post | |
* @return array Meta Keys | |
*/ | |
function custom_fields_meta_box_meta_keys( $meta_keys, $post ) { | |
// Define the meta keys that you want to return | |
// You must specify at least one | |
$keys = array( | |
'key1', | |
'key2', | |
); | |
// Stop editing | |
return $keys; | |
} | |
add_filter( 'postmeta_form_keys', 'custom_fields_meta_box_meta_keys', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment