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
'meta_query' => array( array( 'key' => 'field_63d0017ab088f', 'value' => $current_user->ID, 'compare' => '==' ) )
'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”
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!