Created
December 12, 2017 11:50
-
-
Save mahafuz/9aa69e666f91e09f51c64bdf29dfe0d8 to your computer and use it in GitHub Desktop.
Dropdown attribute with default value in WPBakery Visual Composer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Visual Composer DropDown Item Example in Right Way | |
* Dropdown attribute with default value in WPBakery Visual Composer | |
* | |
* @package VC_Dropdown | |
* @author Mahfuz <asrmahfuz8@gmail.com> | |
*/ | |
vc_map(array( | |
"name" => __( "VC Dropdown", 'textdomain' ), | |
"description" => __( "VC Dropdown items example in right way!!!", 'textdomain' ), | |
"base" => 'base_name', | |
"controls" => "full", | |
"category" => __( 'category_name', 'textdomain' ), | |
"params" => array( | |
array( | |
'type' => 'dropdown', | |
'heading' => __( 'Dropdown Items', 'textdomain' ), | |
'value' => array( | |
__( 'Item One', 'textdomain' ) => '1', | |
__( 'Item Two', 'textdomain' ) => '2', | |
__( 'Item Three', 'textdomain' ) => '3', | |
__( 'Item Four', 'textdomain' ) => '4' | |
), | |
'description' => __( 'Upload member photo.', 'textdomain' ), | |
'param_name' => 'dropdown_items' | |
) | |
) | |
) | |
); |
std is not documented https://kb.wpbakery.com/docs/inner-api/vc_map/#vc_map()-paramsArray
It's a few years ago I wrote that bit of code.. but at time of writing it worked. Here you can read a tutorial about that topic with several comments of other people the code worked for as well:
https://urosevic.net/wordpress/tips/dropdown-defaults-visual-composer/
If I remember right that parameter was not documented years ago either but implemented nevertheless.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@sebastienserre
In case you or anybody else still needs this:
Surprisingly (for me at least) you don't set the default by using the index of your values array. Looking at the source code in backend editor you see that the actual value of your select->option tag is the value of the array item you define here in your dropdown array (for example "Second Option") while the label you get in the backend is what you have here as the index of your array. I had expected to have it the other way around...