I have a bit complex issue that used to work and now suddenly it does not work anymore.
I have a learner cpt with a series of fields. Next, I have a field called qualification. The qualification and learner are in many to many relationships. I need to link the qualification field ( a dropdown with listed qualifications) to the learner add new record field so that qualification can be added to the learner when the learner is captured. I have done it as follow.
Added a qualification field to the "add new learner form" with the following code
<div class="row">
<div class="col-sm-6">
<label>Qualification</label>
[cred_generic_field type='select' field='qualification-field']
{
"options":[add_qualification_field]
Then I have the following function
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 );
}
This used to work however suddenly it stopped working. It was recently addressed with this support ticket.
https://toolset.com/forums/topic/split-publishing-related-many-to-many-posts/
Nigel
Supporter
Les langues:
Anglais (English )
Espagnol (Español )
Fuseau horaire:
Europe/London (GMT+00:00)
Hi Herman
I see you are using the custom code approach suggested by Waqar in that thread.
It involves 3 steps.
One is to add a generic field to your form for submitting learner posts to connect a particular qualification post.
The second is to register a custom shortcode to actually provide the list of qualifications as options to that generic field.
The final part is to process the form on submission and take the chosen qualification option and then connect the learner and qualification posts.
Which bit isn't working?
The generic field in your form doesn't have the notification posts?
Or the posts are not being connected when you submit the form?
Hi NIgel,
It does not connect after submitting the form
Nigel
Supporter
Les langues:
Anglais (English )
Espagnol (Español )
Fuseau horaire:
Europe/London (GMT+00:00)
You didn't list it above, can you confirm that you added the code that uses the cred_save_data hook to connect the posts?
Hi Nigel, yes sorry i just didint copy it in tje code Here is the code used
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( 'learner-qualification', $post_id, $_POST['qualification-field'] );
}
}
Nigel
Supporter
Les langues:
Anglais (English )
Espagnol (Español )
Fuseau horaire:
Europe/London (GMT+00:00)
So, can you add a line to print the $_POST object to your debug file so that you can confirm the qualification field is populated correctly?
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) {
error_log('$_POST object: ' . print_r($_POST, true));
toolset_connect_posts( 'learner-qualification', $post_id, $_POST['qualification-field'] );
}
}