I have a CRED form that creates a new custom post. The user selects from 3 custom taxonomies and fills out a few other custom fields to create the post. I am trying to create the post_title from the 3 taxonomy fields. post_title: Year Make Model.
I have looked at several posts in the forum and I am using this code...
add_action('cred_save_data', 'my_custom_title',10,2);
function my_custom_title($post_id, $form_data) {
if ($form_data['id'] == 1916873) {
// Gather the pieces
$vyear = get_the_terms( $post->ID, 'vehicle-year');
$vmake = get_the_terms( $post->ID, 'vehicle-make');
$vmodel = get_the_terms( $post->ID, 'vehicle-model');
// Put them together
$title = "$vyear $vmake $vmodel;
// Update the post title
$slug = sanitize_title($title);
wp_update_post( array( 'ID' => $post_id, 'post_title' => $title, 'post_name' => $slug ) );
}
}
I was able to get the post title to display array array array, but I cannot figure out how to return the name from the taxonomy array.
get_the_terms() is used to return an array of terms. If get_the_terms() will return single record then you need to use the code as given under: Could you please try following code.
add_action('cred_save_data', 'my_custom_title',10,2);
function my_custom_title($post_id, $form_data) {
if ($form_data['id'] == 1916873) {
// Gather the pieces
$vyear = get_the_terms( $post->ID, 'vehicle-year');
$vmake = get_the_terms( $post->ID, 'vehicle-make');
$vmodel = get_the_terms( $post->ID, 'vehicle-model');
// Put them together -- with name
$title = $vyear[0]->name."-".$vmake[0]->name."-".$vmodel[0]->name;
// Put them together -- with slug
$title = $vyear[0]->slug."-".$vmake[0]->slug."-".$vmodel[0]->slug;
// Update the post title
$slug = sanitize_title($title);
wp_update_post( array( 'ID' => $post_id, 'post_title' => $title, 'post_name' => $slug ) );
}
}
I have given you two examples, one wiht "name" and another one with "slug". You should use one of it.