attachments icon indicating copy to clipboard operation
attachments copied to clipboard

Search with field type select and multiple = true fails

Open acarabott opened this issue 12 years ago • 4 comments
trafficstars

Performing search when the type is set to 'select' and 'multiple' is true always returns no results unless the search term used is ''

functions.php

$fields = array(
    array(
        'name'  => 'caption',
        'type'  => 'select',
        'label' => __( 'Caption', 'attachments'),
        'meta'  => array(
            'allow_null'    => true,
            'multiple'      => true,
            'options'       => array(
                '1' => 'congo'
            )
        )
    )
);

template file

$search_args = array(
    'instance'      => 'photo_gallery_attachments',
    'fields'        => array( 'caption' )
);

$attachments->search( '', $search_args );

I can see why, the meta_query is using 'LIKE' and comparing an array to the string query. I'm just not sure how to make wp_query compare a single value against the stored (and serialized?) array.

Storing

It also seems that the value stored is the index(es) of the selected items, rather than the values, which are more intuitive search terms, e.g. in this case a search for congo would still fail.

acarabott avatar Aug 05 '13 17:08 acarabott

Thank you for the use case. I plan on revising the storage Attachments uses so that we'll be able to perform simple meta queries instead of relying on Attachments' internal search, but that will take some time.

jchristopher avatar Sep 27 '13 15:09 jchristopher

Sounds good. Thanks for the plugin, it's really great, I use it on pretty much every project.

acarabott avatar Sep 29 '13 12:09 acarabott

Any update on this?

zzramesses avatar Sep 10 '14 05:09 zzramesses

No, my other projects have kept me too busy to revisit such a significant change. I am more than willing to take a Pull Request that handles alternative data storage while maintaining backwards compatibility.

jchristopher avatar Sep 10 '14 18:09 jchristopher