Using the same custom field in several groups

Support MB Group Using the same custom field in several groups

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #36747
    TTI LicensingTTI Licensing
    Participant

    Is there a way to use the same custom field in several groups?

    #36748
    TTI LicensingTTI Licensing
    Participant

    Another way to ask the question: "Can a field group be used in more than one custom post type (CPT)?" I basically have a one-to-many relationship (e.g., TypeA CPT can have multiple associated TypeB CPTs). I've created a custom field group called Implementation with a set of fields. I'd like to use the same group (Implementation) with both CPTs. Can I do that or do I need to create a separate custome field group for the child CPT?

    #36759
    Long NguyenLong Nguyen
    Moderator

    Hi David,

    1. Is there a way to use the same custom field in several groups?
    Yes, you can use the same custom fields in many groups (field ID, field type, other settings ...) but one field group has to be registered in one CPT only. Because if the page has two fields with the same ID, only one will be saved value to the database.

    2. Can a field group be used in more than one custom post type (CPT)?
    Like #1, it is possible. If you use the builder to create the field group, you can select multiple post types in the Location option.
    https://docs.metabox.io/extensions/meta-box-builder/#field-group-settings
    With the code, the meta box settings should be

    'post_types' => ['post', 'my-cpt', 'page']

    https://docs.metabox.io/creating-fields-with-code/

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.