Skip Navigation

[Resolved] Create post_title with selected taxonomies in CRED form

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.

Our next available supporter will start replying to tickets in about 0.62 hours from now. Thank you for your understanding.

This topic contains 2 replies, has 2 voices.

Last updated by mellisaB 6 years, 3 months ago.

Assigned support staff: Minesh.

Author
Posts
#296851

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.

#297095

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

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.

#297161

It works, Thank You Minesh!