Support Forum
Support › Meta Box AIO › 2 different taxonomy fields save the value of the last field
Hello! 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.0
Hello,
The taxonomy
field 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.
Hello 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
Alessandro
Hello,
As I said above, the taxonomy
field sets the post terms. The last taxonomy
field will override other taxonomy field values and all taxonomy
fields will display the value of the last field.
If you want to use it as 2 text
fields which is the post meta (not post term), please use the field taxonomy_advanced
.
Read more in the documentation https://docs.metabox.io/fields/taxonomy/
https://docs.metabox.io/fields/taxonomy-advanced/