Custom Fields
Re-Envisioned
Support General looking for best practice: different field groups for one cpt

  • Creator
    Topic
  • #29614
    Ole Poetter
    Participant

    Hi,

    I have one CPT (let's call it "test") with taxonomies (categories).

    For each category I need a different field group.
    In my mind I have following workflow:
    1. in WP backend I chosse "Add new test".
    2. in next step i choose the right categorie
    3. the corresponding field group opens

    But with the conditional logic I dont' get it right.

    Anyone knows a working way and can explain it please to me?

    Kind regards,
    Ole

Viewing 3 replies - 1 through 3 (of 3 total)
  • Author
    Replies
  • #29620
    Long Nguyen
    Moderator

    Hi Ole,

    Please refer to this topic https://metabox.io/support/topic/adding-field-group-for-woocommerce-category/
    to know how to assign a field group (meta box) for a/some specific categories.

    #29624
    Ole Poetter
    Participant

    Hi Long,

    there is a misunderstanding.

    I don't want to add custom fields on term meta.

    What i'm trying to achieve is following:

    I have a CTP "Listing" with some Categories "House", "Car" and so on.

    Now, if I add an post to the "Listing" CPT I want to choose next the categrory "House" to get the "House field group".
    If I want to add a post within the Listing an choose the category "Car" I want display the "Car field group".

    Kind regards,
    Ole

    #29626
    Long Nguyen
    Moderator

    Hi Ole,

    You can use conditional logic to show/hide a meta box when selecting a taxonomy as well. Read more the documentation https://docs.metabox.io/extensions/meta-box-conditional-logic/#using-with-taxonomies

    Here is an example

     $meta_boxes[] = [
            'title'      => __( 'My Meta Box', 'your-text-domain' ),
            'id'         => 'my-meta-box',
            'post_types' => ['test'],
            'visible'    => [
                'when'     => [['tax_input[your_taxonomy_slug]', 'in', [225] ]], // 225 is the term ID
                'relation' => 'or',
            ],
            'fields'     => [
                ...
            ],
        ];
Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.