Skip Navigation

[Resolved] Auto complete post title based on two field values

This support ticket is created 3 years, 9 months ago. 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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by AndreG3332 3 years, 9 months ago.

Assisted by: Shane.

Author
Posts
#1939151

Hi guys,
I am busy with an app and am trying to autofill the post name based on the value of two field. I have been successful in doing it with one of my cred form (add a participant) The code used here was

<?php
/**
 * New custom code snippet (replace this with snippet description).
 */

toolset_snippet_security_check() or die( 'Direct access is not allowed' );

// Put the code of your snippet below this comment.

add_action('cred_save_data', 'func_auto_post_name',10,2);
function func_auto_post_name($post_id, $form_data) {
 
if ($form_data['id']==798) {
        $surname = get_post_meta($post_id, 'wpcf-student_surname', true);
        $first_name = get_post_meta($post_id, 'wpcf-student-first-name', true);
        $cptitle= $surname. ' - ' . $first_name;
        $args = array('ID' => $post_id, 'post_title' => $cptitle);
        wp_update_post($args);
    }
 
} 

This was code added to toolset custom code snippits. Now I am trying to replicate this in another snippet to achieve the same results but for a custom post type called sections. I have changed (copy and paste) the related fields accordingly, however when i activate this snippet, and I run the cred form to add a new record i get an error about a "fatal error on the website. I have tried this with two of my other cpts and on both of them, i get the same error. here is the snippet for the sections cpt that is giving the error

<?php
/**
 * New custom code snippet (replace this with snippet description).
 */

toolset_snippet_security_check() or die( 'Direct access is not allowed' );

// Put the code of your snippet below this comment.

add_action('cred_save_data', 'func_auto_post_name',10,2);
function func_auto_post_name($post_id, $form_data) {
 
if ($form_data['id']==613) {
        $code = get_post_meta($post_id, 'wpcf-section-code', true);
        $name = get_post_meta($post_id, 'wpcf-name-of-section', true);
        $sectiontitle= $code. ' - ' . $name;
        $args = array('ID' => $post_id, 'post_title' => $sectiontitle);
        wp_update_post($args);
    }
 
}

When activated all of the pages on the site give the same error when deactivated it all works perfectly.

#1939905

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Andre,

Thank you for getting in touch.

The problem is that you have both functions active with the same name. This will throw an error because of the duplicate function name.

To resolve this just change the function name of the second one and it should work fine.

Thanks,
Shane

#1940421

My issue is resolved now. Thank you!