attachments
attachments copied to clipboard
Search with field type select and multiple = true fails
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.
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.
Sounds good. Thanks for the plugin, it's really great, I use it on pretty much every project.
Any update on this?
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.