plugin development – How to show dynamic output in the wp_bkery vc_map dropdown?

Question

I am using the wp_bakery page builder plugin. What I am doing is, I have to display the custom output in the dropdown

Expected output

enter image description here

Current Output

enter image description here

if I use the below code then I am getting the correct output.

$params=array(
        'name'     => __('Speaker'),
        'base'     => 'speaker',
        'category' => __(My shortcodes'),
        'class'       => 'js-example-basic-single',
        "icon" => get_template_directory_uri() . "/images/shortcode_slider.png",
        'params'   => array(
            array(
                'type'        => 'dropdown',
                'heading'     => __('Speakers'),
                'param_name'  => 'speakersname',
                'class'       => 'js-example-basic-single',
                'admin_label' => true,
                //'value'       => array($selectSpeaker),
               'value'         => array(__( 'Item One', 'textdomain' )    => '1'), //static added
               'description' => __('Select speakers')
        ))
    );



echo"<pre />";
print_r($params);
vc_map( $params );

array output

Array
(
    [name] => Speaker
    [base] => speaker
     => My shortcodes
    [class] => js-example-basic-single
    [icon] => https://example.com/wordpress/wp-content/themes/testing/images/shortcode_slider.png
    [params] => Array
        (
            [0] => Array
                (
                    [type] => dropdown
                    [heading] => Speakers
                    [param_name] => speakersname
                    [class] => js-example-basic-single
                    [admin_label] => 1
                    [value] => Array
                        (
                            [Item One] => 1
                        )

                    [description] => Select speakers
                )

        )

)

But If I use the below code then I am getting the current output(Screenshot shared above)

$speakerpost_args = array( 'post_type'=>'speaker','post_status' => 'publish', 'posts_per_page' => 80);
$speaker_posts = wp_get_recent_posts($speakerpost_args);
$selectSpeaker="";
foreach ($speaker_posts as $key => $value) {
    $selectSpeaker.="__( 'Item One', 'textdomain' )    => '1',";
}

$params=array(
        'name'     => __('Webinar Speaker'),
        'base'     => 'speaker',
        'category' => __('Hybreed shortcodes'),
        'class'       => 'js-example-basic-single',
        "icon" => get_template_directory_uri() . "/images/shortcode_slider.png",
        'params'   => array(
            array(
                'type'        => 'dropdown',
                'heading'     => __('Speakers'),
                'param_name'  => 'speakersname',
                'class'       => 'js-example-basic-single',
                'admin_label' => true,
                'value'       => array($selectSpeaker), //dynamic value
               //'value'         => array(__( 'Item One', 'textdomain' )    => '1'),
               'description' => __('Select speakers')
        ))
    );



echo"<pre />";
print_r($params);
vc_map( $params ); 

Array output

Array
(
    [name] => Speaker
    [base] => speaker
     =>My shortcodes
    [class] => js-example-basic-single
    [icon] => https://exmple.com/wordpress/wp-content/themes/testing/images/shortcode_slider.png
    [params] => Array
        (
            [0] => Array
                (
                    [type] => dropdown
                    [heading] => Speakers
                    [param_name] => speakersname
                    [class] => js-example-basic-single
                    [admin_label] => 1
                    [value] => Array
                        (
                            [0] => __( 'Item One', 'textdomain' )    => '1' // here is the issue
                        )

                    [description] => Select speakers
                )

        )

)

0
Naren Verma 11 months 2022-11-09T05:09:55-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse