Taxonomy field (ACF) to taxonomy_multiselect (CMB2)
-
Early migration of basic ACF field types to CMB2 is going quite well.
But I could also do with some pointers…
I have an ACF Taxonomy field named “userorg” on a User edit page. It is used to indicate the company a user belongs to, wherein “company” is a taxonomy and terms are the companies.
With the following CMB2 code…
$cmb_user->add_field( array( 'name' => esc_html__( 'Test Taxonomy Multi Checkbox', 'cmb2' ), 'desc' => esc_html__( 'field description (optional)', 'cmb2' ), 'id' => 'userorg', 'type' => 'taxonomy_multicheck', // Or <code>taxonomy_multicheck_inline</code>/<code>taxonomy_multicheck_hierarchical</code> 'taxonomy' => 'company', // Taxonomy Slug // 'inline' => true, // Toggles display to inline ) );
… the company terms list is shown on the User edit page – but the ‘userorg” term value is not showing as selected.
This is likely because ACF stores the wp_usermeta meta_value for this record as a longtext serialised thing…
a:1:{i:0;s:5:"13296";}
The term ID is in there, 13296.
In fact, if I show this field as type “text” instead of “taxonomy_multicheck”, what it shows in the box is “13296”, without the JSON stuff.
Is there any way to leverage this so that CMB2 can properly pick up the term ID as this field type wants?
- The topic ‘Taxonomy field (ACF) to taxonomy_multiselect (CMB2)’ is closed to new replies.