Create multi-select categories VC element for custom post type

// Create multi dropdown param type


vc_add_shortcode_param( 'dropdown_multi', 'dropdown_multi_settings_field' );
function dropdown_multi_settings_field( $param, $value ) {
   $param_line = '';
   $param_line .= '';

   return  $param_line;
}

// getting custom taxonomy list inside vc_before_init action


$taxonomy = 'portfolio';
$categories_array = array();
$categories = get_terms( array(
    'taxonomy' => $taxonomy,
    'hide_empty' => false,
) );
//$categories_array[] = 'All';
foreach( $categories as $category ){
    $categories_array[] = $category->slug;
}

// VC_map param


array(
      "type" => "dropdown_multi",
      "holder" => "span",
       "class" => "",
       "heading" => __( "Portfolio category dropdown", "roadside" ),
       "param_name" => "multiple",
       "value" => $categories_array,
       "description" => __( "Select Portfolio category dropdown here", "roadside" )
       ),

// create an array from comma separated string
$catString = $para[‘multiple’];
$catsArray = explode(‘,’, $catString);

Leave a Reply

Your email address will not be published. Required fields are marked *

Name *

Available for work