Taxonomy Relationship - Taxonomy Field

Support MB Relationships Taxonomy Relationship - Taxonomy FieldResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #33992
    uptwouptwo
    Participant

    Hey,

    I have connected two taxonomies.

    Example:

    City A
    City B
    = District 1

    City C
    City D
    = District 2

    Now I have a CPT in which 2 fields are "City" and "District".
    If you select City A, District 1 should be automatically selected or displayed as the only option.

    I thought I could do this with simple query_args, but it doesn't seem to work. Where is the error?

    
    add_filter( 'rwmb_meta_boxes', 'your_prefix_function_name' );
    
    function your_prefix_function_name( $meta_boxes ) {
        $prefix = 'schulamt_';
        $meta_boxes[] = [
            'title'      => __( 'Daten', 'your-text-domain' ),
            'id'         => 'schwimmhalle',
            'post_types' => ['schwimmhalle'],
            'fields'     => [
                [
                    'name'        => __( 'Stadt', 'your-text-domain' ),
                    'id'          => $prefix . 'stadt',
                    'type'        => 'taxonomy',
                    'taxonomy'    => ['stadt'],
                    'field_type'  => 'select',
                    'placeholder' => __( 'Stadt auswählen', 'your-text-domain' ),
                ],
                [
                    'name'        => __( 'Schulamt', 'your-text-domain' ),
                    'id'          => $prefix . 'schulamt',
                    'type'        => 'taxonomy',
                    'field_type'  => 'select',
                    'placeholder' => __( 'Schulamt auswählen', 'your-text-domain' ),
                    'query_args'  => [
                        'relationship' => [
                            'id'   => 'schulamt-stadt',
                            'from' => get_the_ID(),
                        ],
                    ],
                ],
            ],
        ];
    
    return $meta_boxes;
    }
    
    #34003
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Meta Box does not support showing a field value based on another field value on "live". You need to create some JavaScript code to use AJAX to do that, refer to this topic https://support.metabox.io/topic/dynamically-filled-select-not-saving/

    #34006
    uptwouptwo
    Participant

    Hey, thank you for your response.

    Then let me rephrase my question please.

    Is it possible to automatically (after saving for example) select the associated taxonomy linked to relationship? It does not necessarily have to be an Ajax request!

    Example: City A is selected and after saving District 1 is automatically set as taxonomy.

    I'm just trying to learn how to use the query_args in a taxonomy relationship correctly!

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