Taxonomy Relationship - Taxonomy Field
Support › MB Relationships › Taxonomy Relationship - Taxonomy FieldResolved
- This topic has 2 replies, 2 voices, and was last updated 3 years, 8 months ago by
uptwo.
-
AuthorPosts
-
February 18, 2022 at 11:48 PM #33992
uptwo
ParticipantHey,
I have connected two taxonomies.
Example:
City A
City B
= District 1City C
City D
= District 2Now 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; }February 19, 2022 at 1:22 PM #34003Long Nguyen
ModeratorHi,
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/
February 19, 2022 at 6:06 PM #34006uptwo
ParticipantHey, 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!
-
AuthorPosts
- You must be logged in to reply to this topic.