Support Forum
Hi,
I have created a relationship between custom post type (from) and user (to).
On the CPT page I see a drop down to select a user. However, on the user profile page I also see the selected user instead of the CPT post name. Is this the expected behavior?
From reading the documents, it seems reciprocal relationships can only be for the same type (e.g. post to post or user to user). However, I read a support thread here where the OP described creating a reciprocal relationship between post and user - so I'm confused.
Finally...
For retrieving connected data, I'm able to get the username using the post ID in the following code:
$users = get_users( [
'relationship' => [
'id' => 'client_to_assignment',
'from' => get_post('123'), // You can pass object ID or full object
],
] );
foreach ( $users as $user ) {
echo 'relationship: ' . $user->display_name . '<br />';
}
However, I can't get the post ID/title, etc. using the user ID in the following code. It simply has no output:
$connected = new WP_Query( [
'relationship' => [
'id' => 'client_to_assignment',
'to' => get_current_user_id(), // You can pass object ID or full object
],
'nopaging' => true,
] );
while ( $connected->have_posts() ) : $connected->the_post();
echo $conntected->post_id;
?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php
endwhile;
Please help. Thanks so much!