Home › Forums › Front-end Issues › Query posts by user relationship field › Reply To: Query posts by user relationship field
@marcusw I don’t see anything wrong with your query that should cause it to not function. The value of the field should have quotes around it, otherwise a value like this would also return posts
if the user id you are querying for is “2”, without the quotes the array index 2 would return this post.
The only thing I can think of by looking at your query args is that either $post_type or $current_user_id is incorrect.
Another cause of your issue would be if you originally saved values to the field when it was set to only allow a single user and then you changed the field to allow multiple users. In this case the field value will be holding an integer instead of an array.
This change to the meta query might correct for that
'meta_query' => array( 'relation' => 'OR', array( 'key' => 'shift_volunteers', 'value' => '"' . $current_user_id . '"', 'compare' => 'LIKE' ), array( 'key' => 'shift_volunteers', 'value' => $current_user_id, 'compare' => '=' ), ),
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!
💻 The next ACF Chat Fridays features a live demo of one of our most highly-requested features: registering CPTs and custom taxonomies directly in ACF. Don’t miss it!— Advanced Custom Fields (@wp_acf) February 27, 2023
📆 Friday 3rd March 3pm UTC
👉 Register here - https://t.co/3UtvQbDwNm pic.twitter.com/j4r4ouQtz9
© 2023 Advanced Custom Fields.