How to make each instance of custom WPBakery component unique?

7 Views Asked by At

I've written a custom component WPBakery using vc_map(). The component works fine, but I need to be able to add more than one of them to my page.

I've looked through the documentation and googled, but I can't work out how to differentiate each instance. Currently, a change to a field in one of the instances affects all the rest of them. Obviously it's possible since all of the standard Visual Composer components allow multiple uses on one page.

Here's my code so far, I've removed the functionality as it's not really relevant:

add_shortcode('batchesGrowers', 'batchesGrowers_func');

function batchesGrowers_func ($atts)
{
    if(!is_admin())
        {
        $args = shortcode_atts( 
            array(
                'batchID' => '1',
            ), 
            $atts
        );

    }
}

add_action( 'vc_before_init', 'batchesGrowers_VC' );

function batchesGrowers_VC()
{
   vc_map( array(
      "name" => __( "Growers", "my-text-domain" ),
      "base" => "batchesGrowers",
      "class" => "",
      "category" => __( "Terroir: New", "my-text-domain")  ,
        "params" => array(
            array(
                "type" => "textfield",
                "holder" => "div",
                "class" => "",
                "value" => "1",
                "heading" => __("Batch ID", 'vc_extend'),
                "param_name" => "batchID",
                "description" => "The number of the batch to display Growers from, defaults to 1"
            ),
        
      )    
   ) );
}
0

There are 0 best solutions below