You have helped us with this before, but we're now needing another version of this functionality.
We have created a post form called Free Agent Registration Form here:
hidden link
We are showing this form on this page:
hidden link
We have a custom post type called Free Agent with a field group defined here:
hidden link
The fields in the field group are Name, Session, and then a taxonomy called Tournaments.
All we want is for the Name field to be passed to be the post title of the Free Agent posts that are created by the form.
The code you previously supplied to us was to create the title for Match post types created with a different post form. That code is here:
<?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_custom_post_title',10,2);
function func_custom_post_title($post_id,$form_data ) {
if ($form_data['id']==847) {
$team1_id = $_POST['@team-1-match_parent'];
$team2_id = $_POST['@team-2-match_parent'];
$team1 = get_post($team1_id );
$team2 = get_post($team2_id );
$match_date_timestamp = get_post_meta($post_id, 'wpcf-match-date-and-time', true);
$field_1 = date('m-d-Y h:ia', $match_date_timestamp );
$field_2 =$team1->post_title;
$field_3 = $team2->post_title;
$title = $field_1." - ".$field_2." vs. ".$field_3;
$args = array('ID' => $post_id, 'post_title' => $title );
wp_update_post($args);
}
}
Can you help us modify this code as needed to only show the Name field as the post title? The post form is 1793, so I know 847 needs to be replaced with 1793 here. But I'm not sure what's needed to replace the remaining lines so only the name field is used as the post title.
I was planning to set this up as a stand-alone code snippet. Would this be correct for that?
<?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_custom_free_agent_title',10,2);
function func_custom_free_agent_title($post_id,$form_data ) {
if ($form_data['id']==1793) {
$title = $_POST['wpcf-free-agent-name'];
$args = array('ID' => $post_id, 'post_title' => $title );
wp_update_post($args);
}
}