Support Forum
Support › MB Relationships › Reciprocal relationship, I don't get it...Resolved
Hi
I have created a relationship (projects-services) and ticked Reciprocal relationship checkbox.
I call the relationship between projects and services from my projects page as the following:
$services = MB_Relationships_API::get_connected( [
'id' => 'projects-services',
'from' => get_the_ID(),
'order'=> 'DESC',
'order_from' => get_the_title(),
] );
foreach ( $services as $service ) {
echo $service->post_title;
}
Until so far, no problem but what I have to do if I want to display all projects related to a service from a service page?
I don't get what the Reciprocal relationship checkbox is for?
Or do I have to create another relationship between Services and projects and associate manually all the projects to a service? Double work then...
Thank you to enlight me.
Hi,
The setting reciprocal
helps you to avoid showing two meta boxes (connect to itself) when you set the relation from an object type to itself. Like this
add_action( 'mb_relationships_init', 'your_prefix_function_name' );
function your_prefix_function_name() {
MB_Relationships_API::register( [
'id' => 'post-to-post',
'from' => 'post',
'to' => 'post',
] );
}
Screenshot https://monosnap.com/file/QwbCPB9qCcHF8ToqkNHDqjZbbzUWwU
If you set reciprocal
for different object types (CPT) like your case, the connection meta box only shows on the from
object type page.
Hi, thank you for your reply. So, if I understand correctly, reciprocal cannot be used for different custom types, right?
So, in my case, I have a relationship between projects and services. A project can have several services. I can list services related to a project. But if I want to list all projects related to a service (a service can be related to several projetcs), how can I avoid to create an new relationship between services and projects and redo the work of select projects related to a service?
Is it doable?
I hope I am enough understandable.
Thank you
Hi,
Yes, it is possible. You just need to remove the setting reciprocal
when registering the relationship. If on a project1
post, you select service1
post related then on the post service1
, it will show project1
connected automatically without redoing manually.
Hi
I got it, it works.
Thank you for your help