i have a multiselect field in acf (key=nutzer) which saves the data in the database in this format:
https://www.dropbox.com/s/xyt4e5d80kqt7eh/Screenshot%202014-08-08%2013.03.58.png
a:2:{i:0;s:1:”6″;i:1;s:2:”111″;}
these are IDs of users.
UserID 6 and userID 111. These IDs are assigend to a custom post type called “product”.
Now i want to make a wp query which returns me all posts where userID 6 is assigned to!
this is my current query:
$projekte = new WP_Query( array (
'post_type' => 'product',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'nutzer',
'value' => $user_ID,
'compare' => 'LIKE'
)
)
));
1. this seems not to work at the moment.
2. and how to get sure, that it only returns exact matches? for instance: the keyvalue 11 should not be returned. therefore it might be clever to find values with quotes?! i.e. “11”.
alright i needed nearly an hour to find the solution but here is it:
new WP_Query( array (
'post_type' => 'product',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'nutzer',
'value' => '"'.$user_ID.'"',
'compare' => 'LIKE'
)
)
));