post_title . " | " . $chantier_name; if ($localisation && isset($localisation['city'])) { $title .= " | " . $localisation['city']; } if ($date) { $title .= " | " . $date; } $my_post['post_title'] = $title; wp_update_post($my_post); } add_action('acf/save_post', 'metiers_patrimoine_chantiers_post_updater', 20); /* ----------------------------------------- HANDLE POST UPDATED MESSAGES -----------------------------------------*/ function chantiers_post_updated_messages($messages) { global $post; $post_type = get_post_type($post); $artisan = get_field('artisan', $post->ID); if ($post_type === 'chantiers' && $artisan->ID) { $artisan_link = get_the_permalink($artisan->ID); $messages[$post_type][1] = 'Chantier mis à jour. Voir sur la fiche de l\'artisan'; $messages[$post_type][6] = 'Chantier publié. Voir sur la fiche de l\'artisan'; } return $messages; } add_filter('post_updated_messages', 'chantiers_post_updated_messages'); /* ----------------------------------------- EDIT ARTISAN LINK ON CHANTIER EDIT PAGE -----------------------------------------*/ // add_action('acf/render_field', function ($field) { // // Vérifiez si le champ est celui que vous voulez personnaliser // if ($field['key'] === 'field_6719065f58122') { // if (did_action('acf/render_field/key=field_6719065f58122') % 2 === 0) { // return; // } // $field['rendered'] = true; // $linked_post_id = get_field($field['key']); // if ($linked_post_id) { // $edit_link = get_edit_post_link($linked_post_id); // echo ' Voir la fiche de l\'artisan '; // } // } // }, 10, 1); /* ---------------------------------------------------------------------- GESTION DE LA COLONNE ARTISAN DANS LA LISTE DES POSTS CHANTIERS ------------------------------------------------------------------------*/ // AJOUT D'UNE COLONNE CUSTOM function metiers_patrimoine_add_acf_posts_columns($columns) { global $current_screen; // SUPPRIMER LA COLONNE 'date' if (isset($columns['date'])) { unset($columns['date']); } $new_admin_col_arrays = array_slice($columns, 0, 2, true) + array('artisan' => 'Artisan') + array('date_chantier' => 'Date chantier') + array_slice($columns, 2, count($columns) - 2, true); return array_merge($new_admin_col_arrays); } add_filter('manage_chantiers_posts_columns', 'metiers_patrimoine_add_acf_posts_columns'); /* ---------------------------------------------------------------------- GESTION DE LA VALEUR DE CHAQUE COLONNE ------------------------------------------------------------------------*/ function metiers_patrimoine_handle_posts_custom_columns($column) { $post_id = get_the_ID(); if ($column == 'artisan') { $artisan = get_field('artisan', $post_id); if ($artisan) { $edit_link = esc_url(get_edit_post_link($artisan->ID)); echo ''; echo esc_html($artisan->post_title); echo ''; } } if ($column == 'date_chantier') { $date_chantier = get_field('date', $post_id); echo '

' . $date_chantier . '

'; } } add_action('manage_chantiers_posts_custom_column', 'metiers_patrimoine_handle_posts_custom_columns', 10, 2); function metiers_patrimoine_sortable_columns($columns) { $columns['date_chantier'] = 'date_chantier'; return $columns; } add_filter('manage_edit-chantiers_sortable_columns', 'metiers_patrimoine_sortable_columns'); function metiers_patrimoine_orderby($query) { if (!is_admin()) { return; } $orderby = $query->get('orderby'); if ('date_chantier' == $orderby) { $query->set('meta_key', 'date'); $query->set('orderby', 'meta_value'); } } add_action('pre_get_posts', 'metiers_patrimoine_orderby'); /* --------------------------------------- CUSTOM CONTENT AFTER POST TYPE TITLE ------------------------------------------*/ add_action('edit_form_after_title', function () { $screen = get_current_screen(); if ($screen && $screen->post_type === 'chantiers') { $linked_artisan_id = get_field('artisan'); $return_to = isset($_GET['return_to']) ? $_GET['return_to'] : ''; $edit_artisan_link = get_edit_post_link($linked_artisan_id); ?>
' /> Retour vers la fiche de l'artisan ' /> Retour vers la fiche de l'artisan