mustardBees / cmb-field-select2

Select2 field type for Custom Metaboxes and Fields for WordPress
93 stars 46 forks source link

Clash with Yoast SEO plugin leads to ordering not being maintained #52

Open gyrus opened 3 years ago

gyrus commented 3 years ago

Is there an issue with ordering when using Gutenberg?

I've been using this plugin's drag-and-drop ordering for a while, but this issue has just arisen. The field saves the correct items, but always in the order that they're in in the hidden select (not the drag-and-drop UI).

I've traced this back to /cmb2/includes/CMB2.php line 753 (in save_fields()), where the values in $_POST are passed through - and there, the values for my field are in the order of the hidden select element, not the drag-and-drop UI. Might there be an issue here with the JS - presumably it would have been responsible for re-ordering things before submission, but the Gutenberg environment is interfering with this?

gyrus commented 3 years ago

Looking into this, it seems to be a clash with the Yoast SEO plugin. For some reason Yoast's select2.full.min.js seems to be rewriting the list elements for this custom fields select UI. The elements end up with data-select2-id attributes, but the ID in the data that this Select2 plugin's script.js (line 21) is looking for is gone, creating a JS error when a drag-and-drop happens.

I'm not sure if the Yoast code is interfering where it shouldn't or if the code here isn't written in the right way to not be interfered with?