mustardBees / cmb-field-select2

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

Taxonomy Options #30

Closed Douglas-Marzean closed 8 years ago

Douglas-Marzean commented 8 years ago

I am trying to get this to work with taxonomy in a theme. Not sure where I am going wrong..

    $field_id = INVENTOR_LISTING_PREFIX  . 'locations';
    $field_name = __( 'Location', 'inventor' );
    $cmb->add_field( array(
        'id'            => $field_id,
        'taxonomy'      => 'locations',
        'name'          => apply_filters( 'inventor_metabox_field_name', $field_name, $metabox_id, $field_id, $post_type ),
        'type'          => 'pw_select'
        'default'       => apply_filters( 'inventor_metabox_field_default', null, $metabox_id, $field_id, $post_type ),
        'attributes'    => apply_filters( 'inventor_metabox_field_attributes', array(), $metabox_id, $field_id, $post_type ),
    ) );
mustardBees commented 8 years ago

I've never tried passing in the taxonomy name like this. My understanding is you need to specify an array of options.

We have a couple of helper functions for generating CMB2 style arrays for both posts and terms.

You would also need to write additional code to associate the current object with the selected term.