• Resolved hparra

    (@hparra)


    Hi everyone!

    I have been looking for an answer to this for weeks with no luck, so I hope someone can help.

    I would like to be able to hide certain custom fields in the custom fields metabox of the edit window, as it happens automatically with the ones beginning with an underscore so I can hide, for example, custom fields beginning with “myplugin_”.

    Is there any way to make this possible? I will appreciate any contribution or suggestion, however renaming the custom fields is currently not an option (which would be an easy soltion if possible).

    Thank you and greetings from Spain,
    Hector

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    There are no convenient hooks for this. You would need to create your own metabox based off of the default one that does the filtering. Then remove that default from the form and add in your version. The source code is in wp-admin/includes/meta-boxes.php around line 474 in version 3.5.2.

    Thread Starter hparra

    (@hparra)

    Thank you, bcworkz.

    However, I was finally able to find a filter which works, I am just adding it here for future reference:

    This example will hide a custom field called test1 while respecting the configuration for the others:

    add_filter(‘is_protected_meta’, ‘my_is_protected_meta_filter’, 10, 2);
    function my_is_protected_meta_filter($protected, $meta_key) {
    return $meta_key == ‘test1’ ? true : $protected;
    }

    Regards,
    Hector

    Thread Starter hparra

    (@hparra)

    Marked as resolved 😉

    Moderator bcworkz

    (@bcworkz)

    Cool! I guess I didn’t dig deep enough, sorry for the misinformation. Thanks for posting the solution.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to filter custom fields by name’ is closed to new replies.