Toolset: Auto Generate Post Title and Name/Slug by Combining Other Fields

add_action('cred_save_data', 'build_post_title', 10, 2);
function build_post_title($post_id, $form_data) {
 
if ($form_data['id']==9999) {
$field1 = get_post_meta($post_id, 'wpcf-street_address', true);
$field2 = get_post_meta($post_id, 'wpcf-city_address', true);
$term_list = wp_get_post_terms($post_id, 'state-address', array("fields" => "names"));
$terms = join("-",$term_list);
$field4 = get_post_meta($post_id, 'wpcf-zip_address', true);
 
$post_title=$field1.'-'.$field2.'-'.$terms.'-'.$field4;
$slug = sanitize_title($post_title);
wp_update_post(array('ID'=>$post_id, 'post_title'=>$post_title,'post_name' => $slug));
}
}

Visto en https://toolset.com/forums/topic/auto-generate-post-title-and-nameslug-by-combining-other-fields/

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

Scroll al inicio

We are using cookies on our website

Please confirm, if you accept our tracking cookies. You can also decline the tracking, so you can continue to visit our website without any data sent to third party services.