Support

Account

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.