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.