0

I'm looking for a plugin or sth to let the admin enter a list of specs (name & value) for a given type of post. The regular custom fields would work perfectly but of course, they are used by some other plugins and I don't really want to filter them on my theme (since plugins may be added in the future) and also don't like the admin seeing all that irrelevant/confusing info.

4
  • 2
    If you prefix field names with an underscore, they'll be hidden from the built-in Custom Fields meta box. You can then add your own meta box to manage your specific custom fields. I don't understand the part of your explanation regarding filtering them in your theme or other plugins using post meta.
    – Milo
    Commented Jan 12, 2015 at 22:33
  • Currently, I have a couple of plugins installed that are adding a few custom fields by default to every post. So when the admin wants to add a custom field sees a bunch of them already used and the ones he adds, will be mixed with the existing ones. I want a custom field box, that features no pre-existing fields when creating a new post and that will, in the future show only the ones added manually by the admin.
    – Mauro
    Commented Jan 12, 2015 at 22:39
  • Mauro, by now it's really hard to understand your goal. If you need to (in code) retrieve all registered custom fields for a specific post type, then please edit your question to make that clear. Also show us what you have tried to reach your goal and where you failed with your efforts. Thank you.
    – kaiser
    Commented Jan 12, 2015 at 22:52
  • I want the admin to be able to write custom specs to a product (custom post type). An example would be the list of specs of a cellphone: "Battery life: 48hs, Internal memory: 16GB, etc". I want the admin to be able to write both, label and value. My theme will then print them as a <dl>. Some plugins don't prefix their metadata with an underscore and they show up in the out-of-the-box custom fields meta box. I want to create an extra meta box, with the same functionality, but without these plugin-created meta data.
    – Mauro
    Commented Jan 12, 2015 at 23:03

1 Answer 1

1

Custom fields are also known as post meta. Many things are stored as post meta, such as the ID of the featured image. You'll have noticed that these do not show up in the custom fields section of your posts.

This is because these post meta values have keys beginning with an underscore. Similarly any post meta you set that also has an underscore at the start, will not appear in the custom fields section.

So your task now is to implement the User Interface for the options you want to present to the user. You would do this using custom meta boxes. Luckily this question and many variants of it have been asked by people wanting to create different kinds of meta box. For this reason I won't go in to detail on that here when others have already done so.

This question and answer will give you the basic gist of what to do to create a custom meta box and how to save the value when the post is saved, but others may provide more information or cater to your specific UI needs.

A final note, when registering a metabox, you have to specify where it goes and what capability is needed to view it. This way you can show the box only to those users with the necessary access. For example, administrators and super administrators have the manage_options capability, but not editors. Users can also turn the boxes on and off using the screen options, or collapse them down and rearrange them. You do not need to do anything extra to get these UI features.

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.