From 4c582fdac190c6837034c54e18a0e94f01e66a93 Mon Sep 17 00:00:00 2001 From: Antoine M Date: Wed, 5 Feb 2025 17:17:38 +0100 Subject: [PATCH] renaming portfolio label and passing client in column --- includes/post-types.php | 44 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/includes/post-types.php b/includes/post-types.php index 24bdab7..710a48b 100644 --- a/includes/post-types.php +++ b/includes/post-types.php @@ -26,14 +26,15 @@ function cpt_customer() register_post_type( 'portfolio', array( - 'label' => __('Portfolio'), - 'singular_label' => __('Portfolio'), + 'label' => __('Projets'), + 'singular_label' => __('Projets'), 'public' => true, 'menu_icon' => 'dashicons-forms', 'show_ui' => true, 'hierarchical' => false, 'supports' => array('title', 'thumbnail', 'editor', 'excerpt', 'custom-fields', 'revisions', 'page-attributes'), 'show_in_rest' => true, // Active l'éditeur de blocs (Gutenberg). + 'rewrite' => array('slug' => 'projets'), ) ); @@ -43,3 +44,42 @@ add_action('init', 'cpt_customer'); function my_custom_post_type() {} add_action('init', 'my_custom_post_type'); + + + + +/* ---------------------------------------------------------------------- + DÉCLARATION DES COLONNES CUSTOM DANS LA LISTE DES POSTS ARTISANS + ------------------------------------------------------------------------*/ + +// **** AJOUT DES COLONNES +function deligraph_projets_add_acf_posts_columns($columns) +{ + global $current_screen; + + + $customColumns = array( + 'client' => 'Client', + ); + $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_portfolio_posts_columns', 'deligraph_projets_add_acf_posts_columns'); + + + +/* ---------------------------------------------------------------------- + GESTION DE LA VALEUR DE CHAQUE COLONNE + ------------------------------------------------------------------------*/ +function deligraph_projets_handle_posts_custom_columns($column) +{ + + $post_id = get_the_ID(); + + if ($column == 'client') { + $client = get_field('client_name', $post_id); + if (!$client) return; + echo $client; + } +} +add_action('manage_portfolio_posts_custom_column', 'deligraph_projets_handle_posts_custom_columns', 10, 2);