Home › Forums › Backend Issues (wp-admin) › User relationship field population
I have an odd issue, which i’m not sure is possible.
I have set up a user relationship field which allows you to add users to your list (in a pseudo way as a “friend” or “connection”. The client would like a way to show a list of people who have added you to their account.
I thought that this may be possible with another acf relationship field. But I can’t for the life of me work out how to achieve this.
Any ideas?
Users to users.
Essentially they are connecting to each other, and they want a way to have it so if User A is logged in and User B has added them as a connection that they know this by either an alert on their account page or as a list of people connected to them.
Thats the ideal situation.
Currently using this code, which displays nothing.
The user is returning User Objects. So not sure if this is just missing something to make it work right.
<div class="connectedtoyou usersloop teamloop" style="margin-top:40px!important;margin-bottom:40px!important;display:none!important;">
<hr>
<div class="users">
<h3 class="center centered">Users connected to you</h3>
<?php
$current_user = wp_get_current_user();
$connect_user = 'user_'.$current_user->ID;
$connect_field = get_field('user_follows');
$args = array(
'meta_key' => $connect_field,
'meta_value' => $connect_user,
);
$user_query = new WP_User_Query( $args );
if ( ! empty( $user_query ) ) { ?>
<div class="row isotope">
<?php foreach( $user_query as $user ): ?>
<div class="col fade-up item">
<div class="item-container"><a href="<?php echo get_author_posts_url( $user->id ); ?>" style="text-decoration:none!important;">
<?php if ('health' == get_user_meta($user->ID, 'mepr_select_ident', true)) { ?><img src="<?php echo get_home_url(); ?>/wp-content/uploads/2023/01/D4HGN_Logo_2.png" alt="Health">
<?php } elseif ('design' == get_user_meta($user->ID, 'mepr_select_ident', true)) { ?><img src="<?php echo get_home_url(); ?>/wp-content/uploads/2023/01/D4HGN_Logo_1.png" alt="Design">
<?php } elseif ('research' == get_user_meta($user->ID, 'mepr_select_ident', true)) { ?><img src="<?php echo get_home_url(); ?>/wp-content/uploads/2023/01/D4HGN_Logo_3.png" alt="Research">
<?php } elseif ('global' == get_user_meta($user->ID, 'mepr_select_ident', true)) { ?><img src="<?php echo get_home_url(); ?>/wp-content/uploads/2023/01/D4HGN_Logo_4.png" alt="Global">
<?php } elseif ('network' == get_user_meta($user->ID, 'mepr_select_ident', true)) { ?><img src="<?php echo get_home_url(); ?>/wp-content/uploads/2023/01/D4HGN_Logo_5.png" alt="Network">
<?php } else { ?>
<?php } ?>
<h4 class="darkgrey"><?php echo esc_html( $user->first_name ); ?> <?php echo esc_html( $user->last_name ); ?></h4>
</a></div>
</div>
<?php endforeach; ?>
</div>
<?php } else { ?>
<p>No users are connected to you. <a href="https://d4hgn.com/network/network-users/">Click here to see who's on the network</a>.</p>
<?php } wp_reset_postdata(); ?>
</div>
</div>
Sorry I didn’t get back to this sooner.
I would start by looking and code available for bidirectional relationship fields. The user field works similar to the relationship field but stores data in the usermeta table. I would code a bidirectional user field. I do not know of any existing code for this but it’s possible that someone else has gone down this path already.
Thanks John. I’ll take a look. I wasn’t sure if there was a way of doing a loop (as mentioned above), that would loop through ALL users and highlight those who have added you to their field.
That would then alert users to the fact that User A added you to their list.
You must be logged in to reply to this topic.
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.