Home › Forums › General Issues › Query user and relationship field › Reply To: Query user and relationship field
Hi @mclambert
ACF saves an object (page, term, user, etc) as an ID in the database. Also, the relationship field saves the IDs in a serialized string. Could you please try the following query?
$like = get_posts(array(
'post_type' => 'likes',
'meta_query' => array(
array(
'key' => 'relation_user',
'value' => get_current_user_id(),
'compare' => '='
),
array(
'key' => 'relation_object',
'value' => '"' . get_the_ID() . '"',
'compare' => 'LIKE'
)
)
));
This page should give you more idea about it: https://www.advancedcustomfields.com/resources/querying-relationship-fields/.
I hope this helps. 🙂
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.