bainternet / Tax-Meta-Class

A class for creating WordPress taxonomies custom fields
http://en.bainternet.info/2012/wordpress-taxonomies-extra-fields-the-easy-way
GNU General Public License v3.0
406 stars 111 forks source link

Problems adding options to select field #138

Open DDave995 opened 6 years ago

DDave995 commented 6 years ago

Problems on filling 'options' for select fields.

I'm trying to add multiple options to a select field, if I do this by just filling in keys and values into an array() and using this array into your code it works fine!

$twosectors = array( 'belleza'=>'Belleza', 'centros-estetica'=> 'Centros de estética', 'centros-depilacion-laser'=>'Centros depilación laser', 'centros-manicura-pedicura'=>'Centros manicura y pedicura', 'peluquerias'=>'Peluquerías', 'tatuajes-piercings'=>'Tatuajes y piercings' );

$my_meta->addSelect($prefix.'select_field_id',$twosectors,array('name'=> __('Related sector 1 ','tax-meta'), 'std'=> array('Related ')));


But if I'm trying to do the same but filling keys and values from terms, it does not work... options stay empty. Comparing arrays content they are just the same, why doesn't it work ?

$mysectors = array(); $args = array( 'taxonomy' => 'sector', 'hide_empty' => 0 );

$myterms= get_terms($args); if (isset($myterms) ) { foreach ( $myterms as $myterm ) { $name = $myterm->name; $slug = $myterm->slug; $mysectors[$slug]=$name;

}

}

$my_meta->addSelect($prefix.'select_field_id',$mysectors,array('name'=> __('Related sector 1 ','tax-meta'), 'std'=> array('Related ')));

I would be very happy to get it to work!

Thanks for your marvelous script!