0

I created a custom field that I would like to hide from the wp-admin (because the system generates it and I don't want user to change it; Hidding it with CSS should be OK in this case),

Like this,

 'postal_address' => array(
                            'guid' => 'postal_address',
                            'control' => array(
                                'type' => 'text',
                                'default' => '',
                                'allow_empty' => false
                            ),
                            'label' => 'Postal Address',
                            'help'  => 'Postal Address of Apartment'
                        ),

Wich works,

Problem is that the html element doesn't have any id/class so I can select it and Hide it,

Is there a way to add an html attribute from the definition?

thanks!

2
  • 2
    How did you create the custom field? It seems like you might be using a plug-in, if so you might want to say that ;) Dec 16, 2013 at 19:14
  • YES! true, I should had mention, some reason I thought it would be using standard wp functions anyway, I will rewrite the question.. thanks! Dec 16, 2013 at 19:23

1 Answer 1

1

If you're automatically populating a custom field, you can put an underscore at the beginning of the name ("_postal_address") to hide it in the admin UI.

4
  • Hey! thanks for you answer, but in the code I would need to use the '_name' aswell? thanks again (because I have allready many values stored). BTW: Do you mean in the index? or in the GUID attribute? Dec 16, 2013 at 19:50
  • You should be able to just update the value with update_post_meta(). See codex.wordpress.org/Custom_Fields I don't recognize what your sample code is trying to do, but it looks like it's trying to define a user interface for this field. You won't need that.
    – Dave Ross
    Dec 16, 2013 at 20:10
  • 1
    @DaveRoss I believe the OP is actually using a plug-in so it's not clear what translates to the meta key. It may not be possible. But when using only core, you're right (although you can use this filter too: github.com/WordPress/WordPress/blob/3.8/wp-includes/…) Dec 16, 2013 at 23:05
  • Using an underscore is a horrible way to hide a custom field. A custom field's visibility should not in any way be coupled to its key. Jul 14, 2020 at 13:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.