Hi!
I have custom post type for events and I have select field with “Select multiple values” option enabled.
So user can add event in two or more different types.
This is my code:
$type = $_GET["type"];
$args = array(
'paged' => $paged,
'post_type' => 'events',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'type',
'value' => $type
)
)
);
Before I enabled “Select multiple values” it was working, but after I enabled “Select multiple values” it does not work any more.
I checked this page:
http://www.advancedcustomfields.com/resources/query-posts-custom-fields/
but I could not find solution for my problem.
Any ideas?
Thanks!
When you allow multiple values the values saved is no longer a single text value. Instead it is stored in the DB as a serialized array. You need to alter the meta query, you can see an example of the meta query and it would work the same as the meta query here http://www.advancedcustomfields.com/resources/querying-relationship-fields/#single-location.php. See that page for an explanation of this code.
meta_query = array(
array(
'key' => 'type',
'value' => '"'.$type.'"',
'compare' => 'LIKE'
)
)