Hi Andre,
Sorry if my message resulted in confusion.
What Nigel shared is absolutely correct. When using add new post forms, there is no built-in field available to connect another post which holds a "many-to-many" relationship.
But since your project requires that this connection is made when the add new learner form is submitted, I shared a workaround of using a generic field for this purpose and process the relationship connection on form's submission.
But if for any reason, this is not what you'd prefer and would like to continue on with the new and separate relationship form, you can choose to do that as well. But please note that in that relationship form, all posts from both learners and qualifications will show and to restrict the learner field to a particular one, you'll still need some workaround or custom code/script.
I hope this clarifies and let me know if you still have any questions around this.
Hi Waqar,
Thx for your assistance. I have added the code as suggested however it did not update the qualification fields when I added a new record.
I am summarising the code here so you can maybe see where I missed something.
The field I added to the add new learner form
<div class="row">
<div class="col-sm-6">
<label>Qualification</label>
[cred_generic_field type='select' field='qualification-field']
{
"options":[add_qualification_field]
}
[/cred_generic_field]
The code added to the functions.php file
add_shortcode('add_qualification_field', 'add_qualification_field_func');
function add_qualification_field_func() {
// get all the qualification posts
$args = array(
'post_type' => 'qualification',
'posts_per_page' => -1,
'post_status' => 'publish',
);
$posts_array = get_posts( $args );
foreach ($posts_array as $post) {
$data[] = array('value' => $post->ID, 'label' => $post->post_title );
}
// return the them in json format for the generic field
return(json_encode($data));
}
and the code added to the functions .php file for theadd action
add_action('cred_save_data','update_catalog_rel_func',15,2);
function update_catalog_rel_func($post_id, $form_data) {
if ($form_data['id']==682) {
toolset_connect_posts( 'learners-qualifications', $post_id, $_POST['qualification-field'] );
}
}
I am furthermore adding a screenshot of the "add new learner" and the field was added just before the update button at the bottom of the form
Thanks for the update Andre,
Your steps seem to be correct, but to troubleshoot this further, I'll need access to the website's admin area.
You're welcome to share temporary admin user's details in reply to this message.
(I've set your next reply as private)
Note: Please make a complete backup copy of the website before sharing the access details.
regards,
Waqar
Hi Andre,
Thank you for waiting and I apologize for the delay, as I had an unusually busy queue during the weekend.
During troubleshooting, I noticed the difference in the relationship slug in the code.
In the code, "learners-qualifications" is used ( screenshot: lien caché ), whereas the actual slug is "learner-qualification" ( screenshot: lien caché ).
Please correct the slug in the code and then check the form again.
regards,
Waqar
My issue is resolved now. Thank you!