ThemeFuse / Unyson

A WordPress framework that facilitates the development of WP themes
http://unyson.io
926 stars 220 forks source link

Getting multipicker value from widget settings. #2542

Closed webangon closed 7 years ago

webangon commented 7 years ago

I am using multipicker settings in widget area.

            'display' => array(
                'type' => 'multi-picker',
                'label' => false,
                'desc' => false,
                'picker' => array(
                    'display_type' => array(
                        'type' => 'select',
                        'label' => __('Population', 'chiki'),
                        'desc' => __('Show individual folios or from category', 'chiki'),
                        'choices' => array(
                            'individual' => __('Individual', 'chiki'),
                            'taxonomy' => __('Category', 'chiki')
                        )
                    )
                ),
                'choices' => array(
                    'individual' => array(
                        'individual_id' => array(
                            'type' => 'multi-select',
                            'label' => __('Multi-Select: Posts', 'chiki'),
                            'population' => 'posts',
                            'source' => 'post',
                        )
                    ),
                    'taxonomy' => array(
                        'taxonomy_id' => array(
                            'type'  => 'multi-select',
                            'label' => __('Population', 'chiki'),
                            'desc'  => __('Show post from categories or single category.', 'chiki'),
                             'population' => 'taxonomy',
                             'source' => 'category',
                        )

                    )
                )
            ),

So to get these vaules.

    if (fw_akg('display/display_type', $atts) === 'individual') {

        $options = fw_akg('display/individual', $atts);
        $icon= $instance['individual_id'];
       // var_dump($icon); -- Nothing output

    }

I think fw_akg is not for widget rather its for shortcode .

If I have widget with this settings

    'title' => array(
        'type' => 'text',
        'label' => __('Widget tite', 'webangon'),
    ),

I can get these

$instance['title'];

Is really fw_akg owon't work for widget?

GheorgheP commented 7 years ago

Look at your coed snippet:

if (fw_akg('display/display_type', $atts) === 'individual') {
        $options = fw_akg('display/individual', $atts);
        $icon= $instance['individual_id'];
       // var_dump($icon); -- Nothing output
}

First you get the individual value in $options variable:

 $options = fw_akg('display/individual', $atts);

Then instead of taking the icon from $options, you take it from $instance:

 $icon= $instance['individual_id'];

But it should be:

 $icon= $options['individual_id'];

But you can do it even better:

$icon = (fw_akg('display/display_type', $atts) === 'individual')
    ? fw_akg('display/individual/individual_id', $atts)
    : null //Or whatever you need instead
webangon commented 7 years ago

Thank you . But $icon= $options['individual_id']; works when getting values from shortcode but this is not shortcode, this is in widget . And var_dump of $instance['display'] as follows array(3) { ["display_type"]=> string(8) "taxonomy" ["individual"]=> array(1) { ["individual_id"]=> array(0) { } } ["taxonomy"]=> array(1) { ["taxonomy_id"]=> array(2) { [0]=> string(1) "1" [1]=> string(1) "5" } } }

GheorgheP commented 7 years ago

But how you save the options, this doesn't have to do anything with fw_akg?

webangon commented 7 years ago

I just have checked that fw_akg works fine . Probably I am missing value of $atts in this if(fw_akg('display/display_type', $atts) === 'individual') . How does $atts work in widget?

GheorgheP commented 7 years ago

We do not have any functionality of option type for widgets, so you control all data flow, you render the options, you save them, you defined the $atts value, so you should know what values it contains.