Saltar navegación

[Resuelto] Split: publishing related many-to-many posts

This support ticket is created hace 5 años, 10 meses. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

Etiquetado: ,

Este tema contiene 19 respuestas, tiene 3 mensajes.

Última actualización por AndreG3332 hace 5 años, 9 meses.

Asistido por: Waqar.

Autor
Mensajes
#1216873

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.

#1217880
lms add learner.png

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

#1218822

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

#1220926

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: enlace oculto ), whereas the actual slug is "learner-qualification" ( screenshot: enlace oculto ).

Please correct the slug in the code and then check the form again.

regards,
Waqar

#1222250

My issue is resolved now. Thank you!