Make WordPress Core

Opened 10 years ago

Closed 10 years ago

#36825 closed defect (bug) (duplicate)

Multiselect feature on attachment_fields_to_edit

Reported by: drosendo Owned by:
Priority: normal Milestone:
Component: Media Version:
Severity: normal Keywords:
Cc: Focuses: javascript, administration

Description

Dont know if is bug or not.

When using:

<?php

add_filter('attachment_fields_to_edit', array($this, 'multi_field'), 10, 2);
add_filter('attachment_fields_to_save', array($this, 'multi_field_save'), 10, 2);

function multi_field($form_fields, $post) {
    $current = "something";
    $html = "<select name='attachments[{$post->ID}][multi_field]' id='attachments[{$post->ID}][multi_field]' multiple='multiple'>";
    $html .= "<option value='' " . selected($current, '', false) . ">none</option>";
    $html .= "<option value='a' " . selected($current, $something, false) . ">a</option>";
    $html .= "<option value='b' " . selected($current, $something, false) . ">b</option>";
    $html .= "<option value='c' " . selected($current, $something, false) . ">c</option>";
    $html .= "<option value='d' " . selected($current, $something, false) . ">d</option>";
    $html .= '</select>';

    $form_fields['woosvi-slug'] = array(
        'label' => 'Variation',
        'input' => 'html',
        'html' => $html,
        'application' => 'image',
        'exclusions' => array(
            'audio',
            'video'
        )
    );

    return $form_fields;
}

function multi_field_save($post, $attachment) {

    if (isset($attachment['multi_field']))
        update_post_meta($post['ID'], 'multi_field', $attachment['multi_field']);


    return $post;
}

Each time the select option is done, it runs ajax and saves the last value and not multiple values.
May be im missing somehting to allow this to work properly.

thanks,
David

Change History (1)

#1 @ocean90
10 years ago

  • Component Options, Meta APIsMedia
  • Milestone Awaiting Review
  • Resolutionduplicate
  • Status newclosed
  • Type enhancementdefect (bug)
  • Version 4.5.2

Hello @drosendo, welcome to the WordPress Trac!

Thanks for your valid report, we're already tracking this issue in #28053.

Note: See TracTickets for help on using tickets.