Custom Post Type with Custom Title

You can try the following code.

function custom_post_type_title ( $post_id ) {
    global $wpdb;
    if ( get_post_type( $post_id ) == 'cars' ) {
        $engine=", ".get_post_meta($post_id, 'Engine', true).'l';
        $terms = wp_get_object_terms($post_id, 'brand');
        $abrand= ' '.$terms[0]->name;
        $amodel=" ".$terms[1]->name;
        $title = $post_id.$abrand.$amodel.$engine;
        $where = array( 'ID' => $post_id );
        $wpdb->update( $wpdb->posts, array( 'post_title' => $title ), $where );
    }
}
add_action( 'save_post', 'custom_post_type_title' );

Leave a Comment