Underscores in custom fields

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?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x