Toolset: Update Title and Slug of Post with Custom Field Content when post saves in the WordPress backend
add_filter( 'wp_insert_post_data' , 'set_issue_title' , '10', 3 );
function set_issue_title( $data , $postarr ) {
if ( 'my_post_type' != $data['post_type'] )
return $data;
$post_title = $data['post_title'];
if ( ! $post_title ) {
$issue_number = trim( $_POST['wpcf']['single1'] );
$issue_type = trim( $_POST['wpcf']['single2']);
$issue_title = $issue_type . ' - ' . $issue_number;
$post_slug = sanitize_title_with_dashes ($issue_title,'','save');
$post_slugsan = sanitize_title($post_slug);
$data['post_title'] = $issue_title;
$data['post_name'] = $post_slugsan;
}
return $data;
}
Visto en https://toolset.com/forums/topic/use-custom-field-to-set-title-slug/
Revisar este otro post: https://toolset.com/forums/topic/use-custom-fields-to-set-post-title-and-post-slug/