diff --git a/includes/post_types.php b/includes/post_types.php index 1b31508..245800c 100644 --- a/includes/post_types.php +++ b/includes/post_types.php @@ -26,9 +26,28 @@ function metiers_patrimoine_create_posttype() 'menu_position' => 5.1, - 'supports' => array('title', 'custom-fields'), + 'supports' => array('title', 'custom-fields', 'thumbnail'), ) ); } add_action('init', 'metiers_patrimoine_create_posttype'); + + +function metiers_patrimoine_artisant_post_title_updater($post_id) +{ + if (!$post_id) return; + + $my_post = array(); + $my_post['ID'] = $post_id; + $name = get_field("name", $post_id); + + if (get_post_type() == 'artisans' && $name) { + $my_post['post_title'] = ""; + $my_post['post_title'] = $name; + } + + + wp_update_post($my_post); +} +add_action('acf/save_post', 'metiers_patrimoine_artisant_post_title_updater', 20);