Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I know that using an underscore in front of a custom field name hides it from display on the front-end, e.g. _custom_field_name. In my experience, WordPress also prevents one from adding such a custom field on the front end.

Before I go spelunking around core, I wanted to ask: Is there an "easy" way to allow _custom_fields to be added from wp-admin/post.php?

The reason is this: we rely on hidden custom fields, but when troubleshooting production issues in prod it would be useful to be able to inject certain hidden post meta. I'm not a fan of touching the production database by hand.

what i get

share|improve this question
    
Post your code, please. For what is worth, I don't recall ever having trouble inserting keys with leading underscores. –  s_ha_dum Oct 2 '13 at 18:43
    
Where are you wanting to inject hidden custom fields? On the Editor page or when the post is displayed to the user? –  Charles Clarkson Oct 2 '13 at 19:02
1  
Post my code? There is none relevant to the question. If I'm wrong, my apologies. Re-testing now. @CharlesClarkston exactly, via wp-admin/post.php?post={$ID}&action=edit –  editor Oct 2 '13 at 19:58
    
@s_ha_dum updated to show what I see when trying to add a custom field. –  editor Oct 2 '13 at 20:01
1  
What do you mean by front end? Because it doesn't really seem relevant to this question. The front end is the template, as output by the browser. In that context, post meta data are all the same. –  Chip Bennett Oct 2 '13 at 21:50

2 Answers 2

up vote 5 down vote accepted

I found the following filter, here unlocking all protected meta data:

add_filter( 'is_protected_meta', '__return_false' ); 

Or it can be fine tuned:

add_filter( 'is_protected_meta', function( $protected, $meta_key, $meta_type )
{
    $allowed = array( '_edit_lock', '_test', '_wp_page_template' );
    if( in_array( $meta_key, $allowed ) )
        return false;

    return $protected;
}, 10, 3 );

It allows to display the meta data as well as insert new ones (globally or fine-tuned).

share|improve this answer
    
Thank you good sir! That got way complicated, fast. –  editor Oct 2 '13 at 23:38

Custom fields that begin with an underscore are hidden from the editor. This is so other methods can access them, but they will not show up as "custom fields". For example, this is how most Custom Fields plugins work.

http://codex.wordpress.org/Function_Reference/add_post_meta#Hidden_Custom_Fields

If you wish to bypass this, you should be able to:

http://www.wpbeginner.com/wp-tutorials/how-to-show-hidden-custom-fields-in-wordpress/

share|improve this answer
    
"I know that using an underscore in front of a custom field name hides it from display on the front-end." Sorry, I tried to cover this but must not have been clear enough in my question: What I'm looking for is the ability to leave them hidden for display while allowing them to be added from the "add new" Custom Fields interface. –  editor Oct 2 '13 at 20:37
    
@editor - You should have added this clarification to the Question, I answered without this info... Anyway, I think you cannot have both. . . . GhostToast - that CSS trick ain't working on my side, but even if it did I think it wouldn't suffice. –  brasofilo Oct 2 '13 at 21:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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