Home Forums Feature Requests Meta Key Values in Custom Field Dropdown


Meta Key Values in Custom Field Dropdown

  • I haven’t noticed this reported elsewhere so I’m reporting it.

    I’ve setup Field Groups/Custom Fields to appear conditionally on a custom post type that I’ve created.

    As expected, I do not see these Field Groups when editing a built-in WordPress page/post. However, the ACF meta keys do appear in WordPress’ Custom Fields field group drop-down list (see attched screenshot).

    I’ve written code to remove the ACF meta keys from the drop-down list. However, I would expect ACF to include code that automatically hides meta keys that it creates.

    Ken Chase

  • Hi @kenchase

    Perhaps you could share your code to help identify the problem and solution?


  • 1 – For all of the custom fields that I control the naming of, I prefixed the key with an underscore (i.e. “_my_custom_field”). This prevents them from being displayed in WordPress’ custom fields drop-down list.

    2 – For the custom fields that ACF automatically generates (i.e. when using tabs, ACF uses the “field_51” prefix on the site that I’m working on), I wrote some PHP:

    function kc_hide_meta_keys_start( $num ){
    add_filter( ‘query’, ‘kc_hide_meta_keys_filter’ );
    return $num;
    add_filter( ‘postmeta_form_limit’, ‘kc_hide_meta_keys_start’ );
    function kc_hide_meta_keys_filter( $query ){
    remove_filter( current_filter(), __FUNCTION__ );
    // Match keys beginning with field_51
    $where = “WHERE meta_key NOT LIKE(‘field_51%’);
    $find = “GROUP BY”;
    $query = str_replace( $find, “$where\n$find”, $query );
    return $query;

  • Hi @kenchase

    Thanks for the info. I’m still not sure what the issue is here. Are you asking to have this code as part of the ACF plugin?

  • Hi @elliot

    I would expect any custom fields generated by ACF to be hidden from WordPress’ custom fields drop-down list. Especially if these fields are not associated with the post type being edited (i.e. ACF fields assigned to a custom post type should not be visible when editing a page post type).

    How this is achieved is not important to me, although using the underscore prefix in the ACF plugin’s code is probably the simplest method.

  • Hi @kenchase

    The ACF plugin is a GUI layer for the native custom fields, nothing more, nothing less.

    I can understand that you would like the field names hidden from the dropdown but this is outside the scope of the plugin and can be achieved with a custom filter on your end.


Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘Meta Key Values in Custom Field Dropdown’ is closed to new replies.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.