Skip Navigation

[Résolu] Split: How to populate user name and surname as post title in a cred form – how to check multiple form IDs for same code

This support ticket is created Il y a 5 années. 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.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

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)

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

Dernière mise à jour par israelP Il y a 5 années.

Assisté par: Minesh.

Auteur
Publications
#1378755

I have 2 different credit forms, one records the data into post types of a role and the other one records the data into post types of a different role. The ID of the forms are 2859 and 2886. I have duplicated your code, chaning the ID of the form, but it does not work. How can I solve, please.

Thank you so much.

#1378759

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

You do not need to copy the code, You should try to use the following code:

add_action('cred_save_data','func_custom_post_title',10,2);
function func_custom_post_title($post_id,$form_data) {
 
// form IDs
$forms = array( 2859, 2886 );
  
if ( in_array($form_data['id'], $forms) ){ 
  
           $current_user = wp_get_current_user();
            $user_id = $current_user->ID;
              
             // getting user info based on current user ID
            $user_info = get_userdata($user_id);
      
  
            $name = $user_info->first_name;
            $surname = $user_info->last_name;
  
          
        $title= $name. '-' . $surname;
        $args = array('ID' => $post_id, 'post_title' => $title);
        wp_update_post($args);
    }
}
#1378765

My issue is resolved. Thank you!