Support

Account

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. 🙂