Past post meta into Visual composer Params value

Question

I want to update my lists in Edit Visual composer Element using postmeta data. But it only show yes instead lists.

I use vc_map_update() to check if post meta not empty is change lists.

here my code

    add_action('admin_init', function()
{
    //Get VC gallery shortcode config
    $shortcode_vc_gallery_tmp = WPBMap::getShortCode('vc_teams_cdc');
    
    $orderArray =  get_post_meta($_GET['post'], 'sortable-teams-list', true);//array list
    //Loop over config to find the condition we want to change
    if(!empty($orderArray)){
    foreach($shortcode_vc_gallery_tmp['params'] as $key => $param)
    {
        //We found our parameter to change, woop!
        if($param['param_name'] === 'id_post')
        {
            //Add standard value for gallery size
            $shortcode_vc_gallery_tmp['params'][$key]['value'] = $orderArray;
        }
    }
        }

    //print_r($shortcode_vc_gallery_tmp);

    //VC doesn't like even the thought of you changing the shortcode base, and errors out, so we unset it.
    unset($shortcode_vc_gallery_tmp['base']);

    //Update the actual parameter
    vc_map_update('vc_teams_cdc', $shortcode_vc_gallery_tmp);
}, 100);

How I fetch actual list instead yes only.

here my vc_map()

public function create_teams_cdc() {
    // Stop all if VC is not enabled
    if ( !defined( 'WPB_VC_VERSION' ) ) {
        return;
    }
    
     // query for your post type
    $args = array (  
            'post_type'      => 'teams',  
            'posts_per_page' => -1,               
        );
    
    
    $post_type_query  = new WP_Query(  $args );   
    // we need the array of posts
    $posts_array      = $post_type_query->posts;
    // create a list with needed information
    // the key equals the ID, the value is the post_title
    //~ $array = array( __( '', 'js_composer' ) => 'Pilih' );

    foreach ($posts_array as $posts) {
            
            $array[$posts->post_title]= $posts->ID;

    };
    
    ksort($array);
    


    // Map blockquote with vc_map()
    vc_map( array(
        'name'          => __('Teams', 'teams-cdc'),
        'base'          => 'vc_teams_cdc',
        'description'   => __( 'Teams Cdc', 'teams-cdc' ),
        'category'      => __( 'Vc Layout', 'teams-cdc'),
        'admin_enqueue_js' => preg_replace( '/s/', '%20', get_template_directory_uri() . '/assets/js/admin.js' ),
        // 'icon'           => get_template_directory_uri().'/assets/images/list-icon-cdc.svg',  
        'icon'          => 'icon-wpb-row',
                      
        'params'        => array(

            array(
                'type'          => 'checkbox',
                'class'         => 'title-class',
                'heading'       => __( 'List Teams', 'teams-cdc' ),
                'param_name'    => 'id_post',
                'admin_label'   => false,
                'weight'        => 0,
                'value'         =>  $array,
            ),

            array(
                'type'          => 'textfield',
                'class'         => 'title-class',
                'heading'       => __( 'Add class', 'teams-cdc' ),
                'param_name'    => 'el_class',
                'admin_label'   => true,
                'weight'        => 0,
                'value'         => '',
            ), 
          
        ),
    ));
0
Diana Rider 2 years 2020-12-16T23:10:23-05:00 0 Answers 3 views 0

Leave an answer

Browse
Browse