7

While trying to perform a WP_Query using meta_query(), I had some trouble because the custom fields created by a plugin had _ in the beginning of its name.

Although I noticed it was stored this way in the database, I had no idea why it was there and thought I had to reference it without the underscore (for the record, that is wrong).

Why do some custom fields start with underscores and others don't? What are the underscores used for? Are they mandatory in some circumstances?

13

Custom field names are arbitrary. The underscore hides it from the Custom Fields metabox on the post editing page. When referencing these custom fields in meta_query() or other functions, the underscore has to be used.

Source: conversation with @toscho, @rarst and @wyck in the chat room.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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