From 43410a9337a38a679a985d892424fbc22d84c338 Mon Sep 17 00:00:00 2001 From: Antoine M Date: Mon, 21 Oct 2024 16:58:27 +0200 Subject: [PATCH] handlingpost-type rename --- includes/post_types.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) 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);