How to delete custom field “suggestions” from dropdown list

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.

Read More

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?

Related posts

Leave a Reply

2 comments

  1. 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, "$wheren$find", $query );
    
        return $query;
    }
    
  2. There isn’t a way to filter what appears there, you can see where it queries for keys and renders that field in the function meta_form() in wp-admin/includes/template.php, however you can see that it ignores any key prefixed with an underscore:

    HAVING meta_key NOT LIKE '_%'
    

    this is what plugins should be doing with any meta keys they create to hide those keys from the menu.

    You’ll also see a filter in there, postmeta_form_limit, which is set to 30 by default. You could increase this number so your keys at least get included in the list and don’t fall off the end.

    Another option is to create your own meta box to manage specific meta data, rather than using the Custom Fields meta box.