When you use a standard custom field in WP you have to write the name of the cusotm fields the first time.
The second time you use a custom field it sticks to the custom fields dropdown list. But, sometimes when you install plugins they ise ALOT of custom fields.
This list becomes a bit long an it may “push” som of my custom fields out of tghe list. So, does anyone know how I can remove custom fields from my dropdown list in any easy way?
2 Answers
You can filter the query for these keys on'query'
. I would start that filter as late as possible to avoid side effect.
Sample code, tested:
add_filter( 'postmeta_form_limit', 'wpse_73543_hide_meta_start' );
function wpse_73543_hide_meta_start( $num )
{
add_filter( 'query', 'wpse_73543_hide_meta_filter' );
return $num;
}
function wpse_73543_hide_meta_filter( $query )
{
// Protect further queries.
remove_filter( current_filter(), __FUNCTION__ );
$forbidden = array ( 'the', 'keys', 'you', 'want', 'to', 'hide' );
$where = "WHERE meta_key NOT IN('" . join( "', '", $forbidden ) . "') ";
$find = "GROUP BY";
$query = str_replace( $find, "$where\n$find", $query );
return $query;
}