Is it possible to have a relationship field editable only on one side of the relation? Lets say I have a list of Courses and the list of Applications. I want to select one Course for each Application and I want to see the list of the Applications in the detail of the Course. But I don't want to have a possibility to change anything in the list of the Applications inside the Course detail.
So far, I was able to limit the number of Courses selectable in the Application detail, but I'm not able to disable editing of the Applications in the Course detail.
Is it possible, for example using some class?
Yes, it is possible. You can use the setting
reciprocal when registering the relationship. If you set reciprocal for different object types (CPT) like your case, the connection meta box only shows on the from object type page.
Refer to the documentation https://docs.metabox.io/extensions/mb-relationships/#reciprocal-relationships
I must be very bad at explaining my questions... I clearly stated, that I want to show the metabox in both CPTs. I only want one of them to be disabled for editing. Again, I want to SEE them both, but I don't want to EDIT one of them.
You can use the field type
select and add the attribute
disabled to an object type to disable edit/add more connected objects. For example:
MB_Relationships_API::register( [ 'id' => 'job-to-post', 'from' => [ 'object_type' => 'post', 'post_type' => 'job', 'field' => [ 'type' => 'select', 'disabled' => true //here ] ], 'to' => [ 'object_type' => 'post', 'post_type' => 'post', ], ] );
Read more on the documentation https://docs.metabox.io/extensions/mb-relationships/#syntax
Thank you, I'll will try it, but first I have to say, that I'm usig GUI for creating the relationship. Since there's (probably) not a field for this parameter in there, how should I update my relationship settings? Or do I have to register this relationship only by code?
The builder does not support options to customize the field settings. You need to use the code to get more control over field settings.
OK, I will use the code, but HOW should I do this? Do I need to remove the orginal relationship from the GUI and start from the scratch or can I use some code to change only this option separately?
You can export the relationship from the builder to get the PHP code, move it to the trash or delete it. Then add the code to the file functions.php in the theme/child theme folder.
The data is already saved into the database so don't worry it will be lost after deleting the relationship from the builder.
Refer to this documentation https://docs.metabox.io/extensions/meta-box-builder/#getting-php-code