Hi,
some time ago, you helped me with listing all posts at once in a relationship form.
https://toolset.com/forums/topic/relationship-form-5/
I added javascript and some css, but I cannot save the relationship.
this is where it goes wrong:
<div class="form-group keus">
[create_shadow_parent_field]
<div class="hid">[cred-relationship-role role='child']</div>
</div>
[create_shadow_parent_field] replaces the normal list of posts in a list of all posts.
hid {display:none;}
javascript:
jQuery( document ).ready(function() {
var preSelectedVal = jQuery('#cred_association_zorgaanbieder-nascholing_parent').find(":selected").val();
jQuery("select#nascholing_parent_selector").val(preSelectedVal);
jQuery('select#nascholing_parent_selector').on('change', function() {
var selectVal = this.value;
var selectText = jQuery(this).find("option:selected").text();
if( selectVal > 0) {
jQuery('#cred_association_zorgaanbieder-nascholing_parent').find('option').remove();
jQuery('#cred_association_zorgaanbieder-nascholing_parent').append(jQuery('<option>', { value: selectVal, text: selectText }));
}
else
{
jQuery('#cred_association_zorgaanbieder-nascholing_parent').find('option').remove();
}
});
});
function:
add_shortcode('create_shadow_parent_field', 'create_shadow_parent_field_func');
function create_shadow_parent_field_func() {
$parent_post_slug = 'nascholing';
$relationship_slug = 'zorgaanbieder-nascholing';
$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="">Kies uit de lijst</option>';
foreach ($posts_array as $result) {
if(!in_array($result->ID, $get_results)) {
echo '<option value="'.$result->post_title.'">'.$result->post_title.'</option>';
}
};
echo '</select>';
}
return ob_get_clean();
}