looking for best practice: different field groups for one cpt

Support General looking for best practice: different field groups for one cpt

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #29614
    Ole PoetterOle 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

    #29620
    Long NguyenLong Nguyen
    Moderator

    Hi Ole,

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

    #29624
    Ole PoetterOle 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 NguyenLong 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 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.