Dependency between “custom post type” and “custom fields” in WordPress
In WordPress, a custom post type and custom fields are related in the sense that custom fields are used to store additional information about the custom post type.
Here’s an example of how the dependency works:
- You create a custom post type called “book” using the
- You create custom fields for the “book” custom post type using the
add_meta_boxfunction and the
- When you create a new “book” post, you can fill in the custom fields with information specific to that book, such as the author, publisher and year.
- When you save the “book” post, the custom field values are also saved in the WordPress database and can be retrieved later using the
- You can also display these custom fields in the front-end and use them in your theme’s templates by fetching these values with
In this way, custom fields provide a way to add additional information to custom post types in a structured way, and the custom post type provides a way to organize and display this additional information in the WordPress admin and front-end.