7

I am creating visual composer plugin for price table. I want to add dynamic textfield so user become able to add multiple text fields for item list as want. For now it's showing only one text field but user should able to add multiple fields.

 array (
    "type"          =>  "textfield",
    "heading"       =>  __( 'List Items', 'pt-vc' ),
    "param_name"    =>  "price_list",
    "description"   =>  __( 'Write the list item that you offer', 'pt-vc' ),
    "group"         =>  'List Item',
 ),
Nasir
  • 71
  • 1
  • 5

2 Answers2

9

You can use param_group. Here is the code example.

'params'=> array (
   array(
     'type' => 'param_group',
      'value' => '',
      'heading' =>  __( 'List Items', 'pt-vc' ),
      'param_name' => 'price_list',
       // Note params is mapped inside param-group:
      'params' => array(
          array(
             'type' => 'textfield',
             'value' => '',
             'heading' => __( 'List Items', 'pt-vc' ),
             'param_name' => 'list_itmes',
         )
      )
   )
);

I think answer may be late but help others.

Nand Lal
  • 682
  • 1
  • 11
  • 25
  • How would you pass multiple array values in 'params' array? Please check: https://stackoverflow.com/questions/76803949/wp-bakery-vc-map-param-group-with-array – Toniq Jul 31 '23 at 13:11
3

You may use param_group for that. It's not mentioned in the documentation but you may find it "How To's" https://kb.wpbakery.com/docs/developers-how-tos/use-param-group-in-elements/

Code snippet from link (in case link expires again):

vc_map(
   array(
      'base' => 'your_shortcode',
      'params' => array(
         array(
         'type' => 'textfield',
         'value' => '',
         'heading' => 'Title',
         'param_name' => 'simple_textfield',
         ),
         // params group
         array(
            'type' => 'param_group',
            'value' => '',
            'param_name' => 'titles',
            // Note params is mapped inside param-group:
            'params' => array(
               array(
               'type' => 'textfield',
               'value' => '',
               'heading' => 'Enter your title(multiple field)',
               'param_name' => 'title',
               )
            )
         )
      )
   )
)
wittich
  • 2,079
  • 2
  • 27
  • 50
skyddy
  • 31
  • 2
  • 2
    Could you include a few more details here? Add an example code snippet from the referenced page in case the external link changes or disappears? – AJ X. Dec 28 '16 at 15:34
  • One additional useful thing mentioned in the doc you linked is that you can use the following utility function to parse the shortcode value into an array, when you need to use it: **$titles = vc_param_group_parse_atts( $atts[‘titles’] );** – AncientRo Nov 19 '21 at 10:23
  • How do I pass multiple values to 'titles' at start? – Toniq Jul 31 '23 at 14:12