Skip Navigation

[Resolved] Adding new relationships in front-end forms does not work

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 6 replies, has 3 voices.

Last updated by Minesh 1 year, 3 months ago.

Assisted by: Minesh.

Author
Posts
#2771483

I am trying to:

1) Using Toolset Forms (cred-frontend-editor), attempting to add a new relationship to an existing post.
2) The relationship migration has just recently been run and all plugins are on the latest version.
3) The new "term" is created, but the relationship connection is not being made.
4) Adding this new "term" in the back end editor works, just not the front end.
5) This “term” added through the front end form saves with "CRED Auto Draft" as the title.
6) Deactivating most plugins does not solve this. Some plugins are required for the site to load (Advanced Custom Fields, all Toolset plugins).

Link to a page where the issue can be seen:

Front End:
hidden link (public page)
hidden link (main editing page)
hidden link (term add page)

Backend:
hidden link (term list, see Autodrafts)
hidden link (another term list, more autodrafts)

I expected to see:
1) The new "term" added to the view displaying the relevant list of items on the front end.
2) The new "term" added to the list of items in the back end.

Instead, I got:

1) Term is being created with a CRED Auto Draft (hash) title.
2) Term relationship not created in the Database. If added via the backend directly (new term) or adding the newly created term from the front end (existing term) this relationship is created and the term links as expected.

#2774228

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Somehow - the admin access details you shared with your initial reply is not accessible.

Can you please send me admin access details and let me review your setup and after that I will be able to guide you in the right direction.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2776389

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

When I checked the form I see there is no post title field added to the form:
- hidden link

I see in backend that the post title is set like "ew_expertise 39599" - that is the combination of post type slug and ID of the post. Do you want to keep the same pattern or you want to have the "expertise_title" that is input by user on the form?

#2777026

Either format is fine. It seems like neither of those would end up being unique, so let's go with the expertise_title to make it easier to find.

#2777194

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

What if you try to add the following code to "Custom Code" section offer by Toolset:
=> https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/#adding-custom-php-code-using-toolset
OR
You can add it to your current theme's funcctions.php file:

add_action('cred_save_data','func_generate_automatic_post_title', 10, 3);
function func_generate_automatic_post_title($post_id,$form_data) {
 
    if ($form_data['id']==11418) {
       
        $title=$_POST['wpcf-user__expertise_title']."-".$post_id;

        $args = array('ID' => $post_id, 'post_title' => $title);
        wp_update_post($args);
    }
}

Do you see it working as expected now.

#2777200

It looks like that code snippet does create a title for the expertise, but when using the front-end form it still does not attach it correctly to the expert post_type. This appears to be the case for all of the forms on the front end (hidden link):

Expertise
hidden link
Education
hidden link
Video
hidden link
Link
hidden link

etc.

I'm less concerned about the title, more concerned with the new items not being linked to their parent when added.

#2777375

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello there,

This is a quick follow up to let you know Minesh is not available today but he'll be back shortly and reply to you as soon as possible.

Thank you for your understanding.
Mateus

#2777607

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Then - To connect the post in relationship on fly, you should try to use the following code:

add_action('cred_save_data','func_auto_post_title_attached_parent_on_fly', 10, 3);
function func_auto_post_title_attached_parent_on_fly($post_id,$form_data) {
  

    if(isset($_REQUEST['parent_ew_expert_id'])){
         $parent_id = $_REQUEST['parent_ew_expert_id'];
    }

    if ($form_data['id']==11418) {
        
        $title=$_POST['wpcf-user__expertise_title']."-".$post_id;
 
        $args = array('ID' => $post_id, 'post_title' => $title);
        wp_update_post($args);
         
             $relationship_slug = 'ew_expert_ew_expertise';
        
    }else if($form_data['id']==11482){

            $relationship_slug = 'ew_expert_ew_education';

     }else if($form_data['id']==11519){

             $relationship_slug = 'ew_expert_ew_youtube';
        
    }else if($form_data['id']==11488){

             $relationship_slug = 'ew_expert_ew_links';
    }
     //// connect post in relationship
     toolset_connect_posts($relationship_slug,$parent_id, $post_id);

}

As you may noticed: with the $relationship_slug - you will have to assign the original post relationship slug and parent ID is hold by the URL param "parent_ew_expert_id".

You can connect to other relationship as required.

More info:
- https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_connect_posts
- https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

#2777935

That was the piece I was missing, thank you very much for the quick help and examples.