Home › Forums › General Issues › Get Users with meta query filtering on foreach loop from ACF Users field › Reply To: Get Users with meta query filtering on foreach loop from ACF Users field
this part
'meta_query' => array(
array(
'key' => 'field_63d0017ab088f',
'value' => $current_user->ID,
'compare' => '=='
)
)
should be
'meta_query' => array(
array(
'key' => 'field_63d0017ab088f', // replace this with the field name
// field key will not work
'value' => '"'.$current_user->ID.'"', // enclose ID in quotes
'compare' => 'LIKE' // change to LIKE
)
)
a user field is stored as a serialized array of IDs a strings, so you need to use “LIKE”
example: a:3:{i:0;s:1:"1";i:1;s:1:"2";i:2;s:1:"3";}
This is the serialization of
array("1", "2", "3")
searching for like 1 without the quotes would match all items and not just the first one, so you need to add quotes around your value to get just the fist one.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.