• Resolved reypm

    (@reypm)


    I’ve created a Metabox as follow:

    add_filter( 'rwmb_meta_boxes', 'elclarin_register_meta_boxes' );
    
    function elclarin_register_meta_boxes( $meta_boxes )
    {
        $prefix = 'rw_';
    
        $posts   = get_posts(
            array(
                'post_type'      => 'post',
                'posts_per_page' => 500,
                'post_status'    => 'publish'
            )
        );
    
        $options = array();
        foreach ($posts as $post) {
            if ($post->post_title !== "") {
                $options[$post->ID] = $post->post_title;
            }
        }
    
        // 1st meta box
        $meta_boxes[] = array(
            'id'       => 'related_link',
            'title'    => __( 'Selección de noticias relacionadas' ),
            'pages'    => array('post'),
            'context'  => 'normal',
            'priority' => 'high',
            'fields'   => array(
                array(
                    'name'    => 'Noticia relacionada',
                    'id'      => $prefix.'related_link',
                    'type'    => 'select_advanced',
                    'options' => $options,
                    'clone'   => true,
                    'placeholder' => 'Seleccione una noticia'
                ),
            )
        );
    
        return $meta_boxes;
    }

    This works just fine but it’s possible to remove the selected option before clone the component? What I mean is on pics (linked): first component (holds all the posts), second one (cloned): holds all the posts again and that what I’m trying to prevent since the selected before can’t be there.

    Any advice? How I can achieve that if it’s possible?

    https://ww.wp.xz.cn/plugins/meta-box/

Viewing 1 replies (of 1 total)
  • Plugin Author Anh Tran

    (@rilwis)

    I’m not sure if we can do that easily with select2 library or even with normal select dropdown. The plugin doesn’t support this in its core.

    To do this, you should create a custom field type, enqueue your custom javascript code and handle the clone job in your way. I wrote a documentation for this purpose here, please take a look.

    Thank you.

Viewing 1 replies (of 1 total)

The topic ‘Remove previous selected value when cloning’ is closed to new replies.