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

  • Creator
  • #29614
    Ole Poetter


    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,

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

    Hi Ole,

    Please refer to this topic
    to know how to assign a field group (meta box) for a/some specific categories.

    Ole Poetter

    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,

    Long Nguyen

    Hi Ole,

    You can use conditional logic to show/hide a meta box when selecting a taxonomy as well. Read more the documentation

    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.