Support

Account

Home Forums ACF PRO Quering Group Custom Field with User Object in Post Loop

Solved

Quering Group Custom Field with User Object in Post Loop

  • I am using a group field with the user object as a subfield. I want to setup $args to query only posts that has the current user as this subfield. I cannot find any documentation how to setup the meta key and value for this scenario. Could you explain how to this?

  • ACF stores a list of user IDs as a serialized array.

    The meta key of the field will be "{$group_field_name}_{$sub_field_name}"

    your meta query might look something like this

    
    'meta_query' => array(
      array(
        'key' => "{$group_field_name}_{$sub_field_name}",
        'value => '"'.$user_id.'"',
        'compare' => 'LIKE'
      }
    )
    
  • It took a while to circle back. But this worked perfectly. In my explanation, I mentioned that the subfield was the user object, but that was not correct: the output type was user object but the user ACF field indeed saves the user id. Thanks a lot!!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.