1

Beginner's question: Looking for example how to create a custom post type with additional elements. What I mean is: in my code I have a basic stuff like 'title', 'editor' ... but I need also for example 'start', 'end' - date fields or 'color'. How to achieve this?

1 Answer 1

0

You can use add_meta_box (see also User Contributed Notes for examples) to add custom fields to your custom post type. If you don't feel like adding the metaboxes by yourself, you can also use a custom fields plugin (E.g. Advanced Custom Fields, CMB2, Pods, Carbon Fields.. I'm not affiliated to any of these) to do it for you.

There are good articles, with code examples, about custom meta fields and custom post types on the developer handbook. You should check them out.

If you need to group the custom posts or do sorting or searching based on the extra information (color, maybe?), then consider using custom taxonomy instead.

1
  • Ooh thank you Antti, and no no no, I don't want use any plugins, I would like to learn how to do it programatically. :P
    – Rob D. A.
    Feb 28, 2019 at 16:23

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.