How to create a custom post type with additional fields?

admin2025-01-08  5

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?

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?

Share Improve this question asked Feb 28, 2019 at 16:01 Rob D. A.Rob D. A. 1332 silver badges10 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736266479a1124.html

最新回复(0)