Unyson
Unyson copied to clipboard
Display array values from multi-select option type
I am trying to get array values from multi-picker option types.
'taxonomy_id' => array(
'type' => 'multi-select',
'label' => __('Categories', 'webangon'),
'desc' => __('Select categories to post display', 'webangon'),
'population' => 'array',
'choices' => array(
'1' => __('Daily', 'webangon'),
'2' => __('Weekly', 'webangon'),
'3' => __('Monthly', 'webangon'),
'4' => __('All', 'webangon'),
),
),
How can I print Daily ,Weekly Monthly strings.
I have tried
foreach($instance['taxonomy_id'] as $cat_id => $value){
echo $value.' is begin with ('.$cat_id.')';
}
But I am getting this
1 is begin with (0)
2 is begin with (1)
3 is begin with (2)
4 is begin with (3)
The Daily, Weekly, Monthly and All are just visual representation of the 1,2,3,4 values for the multi-picker option type, they are not stored in the database, only the 1,2,3,4 values are stored.
What you can do for this, in case you need them in option and in frontend too, is to create a function for that list:
function my_days_list() {
return array(
'1' => __( 'Daily', 'webangon' ),
'2' => __( 'Weekly', 'webangon' ),
'3' => __( 'Monthly', 'webangon' ),
'4' => __( 'All', 'webangon' ),
);
}
Use it in your option:
'taxonomy_id' => array(
'type' => 'multi-select',
'label' => __( 'Categories', 'webangon' ),
'desc' => __( 'Select categories to post display', 'webangon' ),
'population' => 'array',
'choices' => my_days_list(),
),
And use it to render the saved values:
foreach ( (array) fw_get_db_settings_option( 'taxonomy_id' ) as $item ) {
echo fw_akg( $item, my_days_list() );
}
Just cameback a while ago. That works !! Thanks