Thank you for waiting and I apologize for the delay in getting back on this.
During testing and research, I couldn't find any built-in function or option to change the behaviour of the post-relationship selection field.
To have a regular select field, which shows all parent "EHRs" posts, you can follow these steps, as a workaround:
1. You'll need to register a custom shortcode, which can get the list of all available parent "EHRs" posts and create a custom regular select field, which includes only those posts as options, which are not already connected:
add_shortcode('create_shadow_parent_field', 'create_shadow_parent_field_func');
function create_shadow_parent_field_func() {
$parent_post_slug = 'ehr';
$relationship_slug = 'ehr-relationship';
$current_post = do_shortcode('[wpv-post-id]');
// get parent posts which are already connected
$get_results = toolset_get_related_posts($current_post, $relationship_slug, 'child', 9999, 0, array(), 'post_id', 'parent');
// get all the parent posts
$args = array(
'post_type' => $parent_post_slug,
'posts_per_page' => -1,
'post_status' => 'publish',
);
$posts_array = get_posts( $args );
// create a custom select field from the available parent posts, which are not already connected
ob_start();
if(!empty($posts_array)) {
echo '<select id="shadow_parent_selector" name="shadow_parent_selector"><option value="">-select-</option>';
foreach ($posts_array as $result) {
if(!in_array($result->ID, $get_results)) {
echo '<option value="'.$result->ID.'">'.$result->post_title.'</option>';
}
};
echo '</select>';
}
return ob_get_clean();
}
The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.
2. Next, in your relationship form, you can hide ( but not remove ) the actual parent post field added through the "cred-relationship-role" shortcode and include this custom select field, by adding this new shortcode [create_shadow_parent_field].
3. And in the form's JS editor, you'll include this script that will detect selection changes in this custom select field and update them in the hidden parent selection field:
jQuery( document ).ready(function() {
jQuery('select#shadow_parent_selector').on('change', function() {
var selectVal = this.value;
var selectText = jQuery(this).find("option:selected").text();
if( selectVal > 0) {
jQuery('#cred_association_ehr-relationship_parent').find('option').remove();
jQuery('#cred_association_ehr-relationship_parent').append(jQuery('<option>', { value: selectVal, text: selectText }));
}
else
{
jQuery('#cred_association_ehr-relationship_parent').find('option').remove();
}
});
});
As a result, the user will see the regular select field which shows all options at once, but, the selection will be updated in the actual autocomplete field too.
I hope this helps and please let me know if you need any further assistance around this.
Note: The custom code examples from our forum are shared to get you started in the right direction. You're welcome to adjust them as needed and for more personalized customization assistance, you can consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/