WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

#36825 closed defect (bug) (duplicate)

Multiselect feature on attachment_fields_to_edit

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

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
3 years ago

  • Component changed from Options, Meta APIs to Media
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed
  • Type changed from enhancement to defect (bug)
  • Version 4.5.2 deleted

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.