2 different taxonomy fields save the value of the last field
Support › Meta Box AIO › 2 different taxonomy fields save the value of the last field
- This topic has 4 replies, 2 voices, and was last updated 2 years, 2 months ago by
Peter.
-
AuthorPosts
-
September 7, 2023 at 11:32 PM #43174
Alessandro Lioce
ParticipantHello! I added 2 metaboxes to the product category of woocommerce.
Sample code
add_filter( 'rwmb_meta_boxes', function ( $meta_boxes ) { $meta_boxes[] = array( 'title' => __( 'Box 1', 'lang' ), 'taxonomies' => 'product_cat', 'fields' => array( [ 'type' => 'taxonomy', 'name' => esc_html__( 'Category', 'lang' ), 'id' => 'field_1', 'taxonomy' => 'product_cat', 'field_type' => 'select_advanced', ], ), ); $meta_boxes[] = array( 'title' => __( 'Box 2', 'lang' ), 'taxonomies' => 'product_cat', 'fields' => array( [ 'type' => 'taxonomy', 'name' => esc_html__( 'Category', 'lang' ), 'id' => 'field_2', 'taxonomy' => 'product_cat', 'field_type' => 'select_advanced', ], ), ); return $meta_boxes; } );If I select a category only in box 1 and save, the empty value is saved.
If, however, I select a category in box 2 and save, both selects show the value I entered in box 2 even if the 2 fields have different IDs.
So it always seems to save the value of the last taxonomy field.The problem only occurs if the 2 taxonomy fields have the same configuration for the taxonomy attribute ('taxonomy' => 'product_cat').
Woocommerce version 8.0.3
WP version 6.3.1
Metabox version 5.7.5
Meta Box AIO version 1.23.0September 8, 2023 at 10:30 PM #43183Peter
ModeratorHello,
The
taxonomyfield sets the post-term so if you have two fields on a page, one will not work properly and it is expected. You should use one taxonomy field only.September 8, 2023 at 11:43 PM #43184Alessandro Lioce
ParticipantHello Peter,
why "it is expected"?
In my case I need to have 2 taxonomic fields for 2 different purposes in WooCommerce "product_cat" taxonomy.
Why shouldn't it be possible to have 2 taxonomy fields with same configuration for the taxonomy attribute ('taxonomy' => 'product_cat')?
Why can I use 2 text fields, but not 2 taxonomy!?
Can you fix it?Thank you
AlessandroSeptember 8, 2023 at 11:47 PM #43185September 11, 2023 at 11:10 PM #43208Peter
ModeratorHello,
As I said above, the
taxonomyfield sets the post terms. The lasttaxonomyfield will override other taxonomy field values and alltaxonomyfields will display the value of the last field.If you want to use it as 2
textfields which is the post meta (not post term), please use the fieldtaxonomy_advanced.Read more in the documentation https://docs.metabox.io/fields/taxonomy/
https://docs.metabox.io/fields/taxonomy-advanced/ -
AuthorPosts
- You must be logged in to reply to this topic.