Can't figure out how to use an ACF custom field with multiple values in WP Advanced Search form.
I'm working on a faceted search using Advanced Custom Fields and WP Advanced Search, and most problems I've run into I've been able to figure out on my own or eventually find someone doing something similar.
So far however, I can't find any example of how to use a custom field with multiple values. I don't know how to set up my WPAS form to address each individual value, or if it's even possible.
This custom field only stores a single value for post, in which case meta_value in wp_postmeta is just the expected string ie. Condo, Townhouse, Detached, etc. This is working fine...
$args['fields'][] = array( 'type' => 'meta_key',
'meta_key' => 'property_style',
'format' => 'multi-select',
'compare' => 'LIKE',
'data_type' => 'ARRAY<CHAR>',
'relation' => 'OR',
'label' => 'Property Style',
'values' => array(
'Condo Townhouse' => 'Condo Townhouse',
'Condo Apartment' => 'Condo Apartment',
'Detached' => 'Detached',
'Semi-Detached' => 'Semi-Detached',
'Freehold Townhouse' => 'Freehold Townhouse',
'Link' => 'Link',
'Other' => 'Other'
)
);
This ACF field accepts multiple values. Storing them is not an issue. The multi-select generated by ACF works fine, as does my importer, but I can't seem to understand how to set up the 'data_type' and 'compare' values to actually address those individual values... My theory is 'data_type' needs to reflect the structure of the array represented by the string stored in meta_value (see question) but I can't quite figure it out...
$args['fields'][] = array( 'type' => 'meta_key',
'meta_key' => 'basement',
'format' => 'multi-select',
'compare' => 'LIKE',
'data_type' => 'ARRAY<CHAR>',
'relation' => 'OR',
'label' => 'Basement',
'values' => array(
'Apartment' => 'Apartment',
'Crawl Space' => 'Crawl Space',
'Finished Walk Out' => 'Finished Walk Out',
'Finished' => 'Finished',
'Full' => 'Full',
'Half' => 'Half',
'None' => 'None',
'Other' => 'Other',
'Partial Basement' => 'Partial Basement',
'Partially Finished' => 'Partially Finished',
'Separate Entrance' => 'Separate Entrance',
'Unfinished' => 'Unfinished',
'Walk Out' => 'Walk Out',
'Walk-Up' => 'Walk-Up'
));
The meta data for the multi-select field looks like this, if it helps:
--------------------------------------------------------------------------------------------+
| meta_id | post_id | meta_key | meta_value |
+---------+---------+-----------+-----------------------------------------------------------+
| 150263 | 5286 | _basement | field_5cf59fb01a564 |
| 150262 | 5286 | basement | a:1:{i:0;s:9:"Apartment";} |
| 150025 | 5276 | _basement | field_5cf59fb01a564 |
| 150026 | 5276 | basement | a:1:{i:0;s:9:"Apartment";} |
| 149792 | 5255 | _basement | field_5cf59fb01a564 |
| 149793 | 5255 | basement | a:2{i:0;s:8:"Finished";i:1;s:4:"Full";} |
| 149531 | 5238 | _basement | field_5cf59fb01a564 |
| 149532 | 5238 | basement | a:2{i:0;s:9:"Apartment";i:1;s:17:"Separate Entrance";} |
| 149278 | 5220 | _basement | field_5cf59fb01a564 |
| 149279 | 5220 | basement | a:2{i:0;s:9:"Apartment";i:1;s:8:"Finished";} |
| 149023 | 5199 | _basement | field_5cf59fb01a564 |
| 149024 | 5199 | basement | a:2{i:0;s:8:"Finished";i:1;s:17:"Separate Entrance";} |
I know I'm doing it wrong and can't find even a hint of info on what I should be doing instead. I'm not sure WP Advanced Search is even still in development but it's still functioning with the latest release of WP so not really my concern.