Skip to content

Instantly share code, notes, and snippets.

@hasanm95
Created November 9, 2016 14:06
Show Gist options
  • Save hasanm95/572ed4c4660b05ad05f5296310da598a to your computer and use it in GitHub Desktop.
Save hasanm95/572ed4c4660b05ad05f5296310da598a to your computer and use it in GitHub Desktop.
Create visual composer with param_group
//Backend visual composer add-on code
vc_map(array(
'name' => 'Accordions',
'base' => 'maxima_accordion',
'category' => 'Maxima',
'params' => array(
array(
'type' => 'textfield',
'name' => __('Title', 'rrf-maxima'),
'holder' => 'div',
'heading' => __('Title', 'rrf-maxima'),
'param_name' => 'title',
),
array(
'type' => 'param_group',
'param_name' => 'values',
'params' => array(
array(
'type' => 'textfield',
'name' => 'label',
'heading' => __('Heading', 'rrf-maxima'),
'param_name' => 'label',
),
array(
'type' => 'textarea',
'name' => 'Content',
'heading' => __('Content', 'rrf-maxima'),
'param_name' => 'excerpt',
)
)
),
),
));
//shortcode
function maxima_accordion_shortcode($atts){
extract(shortcode_atts(array(
'title' => '',
'values' => '',
), $atts));
$list = '<h4>'.$title.'</h4>';
$values = vc_param_group_parse_atts($atts['values']);
$new_accordion_value = array();
foreach($values as $data){
$new_line = $data;
$new_line['label'] = isset($new_line['label']) ? $new_line['label'] : '';
$new_line['excerpt'] = isset($new_line['excerpt']) ? $new_line['excerpt'] : '';
$new_accordion_value[] = $new_line;
}
$idd = 0;
foreach($new_accordion_value as $accordion):
$idd++;
$list .=
'<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapse'.$idd.'">
'.$accordion['label'].'
<span class="fa fa-plus"></span>
</a>
</h4>
</div>
<div id="collapse'.$idd.'" class="panel-collapse collapse">
<div class="panel-body">
<p>'.$accordion['excerpt'].'</p>
</div>
</div>
</div>';
endforeach;
return $list;
wp_reset_query();
}
add_shortcode('maxima_accordion', 'maxima_accordion_shortcode');
@mshshuvooo
Copy link

Thanks a lot.

@rozuja
Copy link

rozuja commented Oct 28, 2019

I know this is old, how can I get the first value of the repeater.

Im using this reapeater with 1 text field, I need to grab the first item of that array.

Any chance for the help!!

@jayeshhpatel
Copy link

Thanks a lot.

@eltongonc
Copy link

I know this is old, how can I get the first value of the repeater.

Im using this reapeater with 1 text field, I need to grab the first item of that array.

Any chance for the help!!

@rozuja Don't think you need any more, but it might help someone in the future:

You can get the values by calling vc_param_group_parse_atts([the param_group]) function.
for example if you have a param_group with param_name titles, use:

$titles = vc_param_group_parse_atts( $atts['titles'] );

$titles[0]; // will return the first title in that list

@aproni34f
Copy link

Is htere a way to pass values to label and excerpt on start for multiple fields? So to have multiple fields visible on start with predefined values?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment