Sauter la navigation

[Résolu] relationship field not working

This support ticket is created Il y a 5 années et 8 mois. 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Ce sujet contient 5 réponses, a 2 voix.

Dernière mise à jour par Nigel Il y a 5 années et 8 mois.

Assisté par: Nigel.

Auteur
Publications
#1225585

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/

#1225647

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?

#1225753

Hi NIgel,
It does not connect after submitting the form

#1225934

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?

#1227190

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'] );
         
    }
}
#1227751

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'] );
          
    }
}