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); /* --------------------------- CUSTOM CODE FOR TITLE ---------------------------*/ add_action('edit_form_after_title', function () { // Vérifie si on est sur le bon post type $screen = get_current_screen(); $last_modified_date = get_the_modified_date('j F Y'); if ($screen && $screen->post_type === 'artisans') { echo '

' . get_the_title() . '

'; // echo '

Dernière modification : ' . $last_modified_date . '

'; } }); function add_last_modified_date_to_publish_box() { global $post; // Vérifiez que vous êtes dans un post et que l'ID du post est valide if ($post && $post->ID) { // Récupérer la date de dernière modification $dashicon = ''; $last_modified_date = get_the_modified_date('j F Y \à H:i', $post->ID); // Afficher la date de dernière modification dans le panneau echo '
'; echo $dashicon . ' Dernière update : '; echo $last_modified_date; echo '
'; } } add_action('post_submitbox_start', 'add_last_modified_date_to_publish_box'); /* --------------------------- CUSTOM CHANTIER META BOX AT THE END OF THE PAGE ---------------------------*/ add_action('add_meta_boxes', function () { // Ajout de la metabox uniquement pour le post type 'artisans' add_meta_box( 'admin_artisan_chantier_list', // ID de la metabox 'Chantiers réalisé par l\'entreprise', // Titre de la metabox 'render_custom_chantier_box_content', // Fonction de rendu 'artisans', // Post type 'normal', // Contexte 'low' // Priorité ); }); /** * Fonction de rendu du contenu de la metabox. */ function render_custom_chantier_box_content($post) { $args = array( 'post_type' => 'chantiers', 'posts_per_page' => -1, 'post_status' => 'publish', 'meta_query' => array( array( 'key' => 'artisan', 'value' => $post->ID, 'compare' => '=', ), ), ); $chantiers = new WP_Query($args); // Afficher les chantiers if ($chantiers->have_posts()) { echo '

Chantiers réalisé par l\'entreprise

'; echo ''; } else { echo '

Chantiers réalisés

'; echo '

Aucun chantier pour cette entreprise

'; echo 'Ajouter un chantier'; } } /* ---------------------------------------------------------------------- SUPPRIMER LA COLONNE RANK MATH SEO SI ELLE EST PRÉSENTE ------------------------------------------------------------------------*/ function remove_rank_math_seo_column_for_artisans($columns) { if (isset($columns['rank_math_seo_details'])) { unset($columns['rank_math_seo_details']); } return $columns; } // Appliquer le filtre uniquement pour le post type "artisans" add_filter('manage_artisans_posts_columns', 'remove_rank_math_seo_column_for_artisans', 20); /* ---------------------------------------------------------------------- DÉCLARATION DES COLONNES CUSTOM DANS LA LISTE DES POSTS ARTISANS ------------------------------------------------------------------------*/ // **** AJOUT DES COLONNES function metiers_patrimoine_artisans_add_acf_posts_columns($columns) { global $current_screen; // SUPPRIMER LA COLONNE 'date' if (isset($columns['date'])) { unset($columns['date']); } $customColumns = array( 'metiers' => 'Métiers', 'elements' => 'Éléments du bâtiment', 'conseiller' => 'Conseiller', 'status' => 'Statut', 'lastmodified' => 'Dernière modification', 'onlinedate' => 'Mise en ligne' ); $new_admin_col_arrays = array_slice($columns, 0, 2, true) + $customColumns + array_slice($columns, 2, count($columns) - 2, true); return array_merge($new_admin_col_arrays); } add_filter('manage_artisans_posts_columns', 'metiers_patrimoine_artisans_add_acf_posts_columns'); /* ---------------------------------------------------------------------- GESTION DE LA VALEUR DE CHAQUE COLONNE ------------------------------------------------------------------------*/ function metiers_patrimoine_artisans_handle_posts_custom_columns($column) { $post_id = get_the_ID(); if ($column == 'conseiller') { $conseiller = get_field('conseiller', $post_id); if (!$conseiller) return; echo $conseiller['user_firstname'] . ' ' . $conseiller['user_lastname']; } if ($column == 'status') { $status = get_field('mdp_status', $post_id); if (!$status || !isset($status['label'])) return; echo '
' . $status['label'] . '
'; } if ($column == 'metiers') { $terms = get_the_terms($post_id, 'metiers'); if ($terms) { $parent_terms = array_filter($terms, function ($term) { return $term->parent == 0; }); // if (empty($parent_terms)) { // echo '

Aucun métier parent

'; // return; // } echo '
'; foreach ($terms as $term) { echo ''; echo esc_html($term->name); echo ''; } echo '
'; } else { echo '

×

'; } } if ($column == 'elements') { $terms = get_the_terms($post_id, 'elementsbatiments'); if ($terms) { $parent_terms = array_filter($terms, function ($term) { return $term->parent == 0; }); echo '
'; foreach ($terms as $term) { echo ''; echo esc_html($term->name); echo ''; } echo '
'; } else { echo '

×

'; } } if ($column == 'lastmodified') { // $last_modified_date = get_the_modified_date('j F Y \à H:i', $post_id); $last_modified_date = get_the_modified_date('d/m/Y', $post_id); if (!$last_modified_date) return; echo $last_modified_date; } if ($column == 'onlinedate') { $published_date = get_the_date('d/m/Y', $post_id); if (!$published_date) return; echo $published_date; } } add_action('manage_artisans_posts_custom_column', 'metiers_patrimoine_artisans_handle_posts_custom_columns', 10, 2); /* ---------------------------------------------------------------------- GESTION DDU FILTRAGES PAR METIERS ------------------------------------------------------------------------*/ // **** CREATION DU DROPDOWN SELECT AVEC LES OPTIONS function metiers_patrimoine_filter_posts_per_metiers_declare_dropdown() { global $pagenow; $post_type = (isset($_GET['post_type'])) ? $_GET['post_type'] : 'post'; //only add filter to post type you want if ($post_type == 'artisans') { $metiers_by_parent = getAllMetiersTermsByParents(); ?> query_vars['tax_query'] = array( array( 'taxonomy' => 'metiers', 'field' => 'slug', 'terms' => $_GET['metiers'], 'include_children' => true, ), ); } } add_filter('parse_query', 'metiers_patrimoine_filter_post_by_metiers_query');