carhop__dynamiques-theme__P.../includes/revues-columns.php
Nonimart 3cccbb76e8
All checks were successful
continuous-integration/drone/push Build is passing
REFACTOR Reorganising columns settings in 2 separates files for each post type
2025-08-13 09:43:47 +02:00

74 lines
2.0 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/* ----------------------------------------------------------------------
DÉCLARATION DES COLONNES CUSTOM DANS LA LISTE DES POSTS ARTISANS
------------------------------------------------------------------------*/
// **** AJOUT DES COLONNES
function carhop_revues_add_posts_columns($columns)
{
global $current_screen;
// SUPPRIMER LA COLONNE 'date'
if (isset($columns['date'])) {
unset($columns['date']);
}
$customColumns = array(
'revue_issue_number' => 'Numéro',
'publication_date' => 'Date de publication',
);
$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_revues_posts_columns', 'carhop_revues_add_posts_columns');
// **** RENDRE LA COLONNE TRIABLE
function carhop_revues_make_columns_sortable($columns)
{
$columns['revue_issue_number'] = 'revue_issue_number';
return $columns;
}
add_filter('manage_edit-revues_sortable_columns', 'carhop_revues_make_columns_sortable');
// **** LOGIQUE DE TRI PERSONNALISÉ
function carhop_revues_custom_orderby($query)
{
if (!is_admin()) {
return;
}
$orderby = $query->get('orderby');
if ('revue_issue_number' == $orderby) {
$query->set('meta_key', 'issue_number');
$query->set('orderby', 'meta_value_num');
}
}
add_action('pre_get_posts', 'carhop_revues_custom_orderby');
/* ----------------------------------------------------------------------
GESTION DE LA VALEUR DE CHAQUE COLONNE
------------------------------------------------------------------------*/
function carhop_revues_handle_posts_custom_columns($column)
{
$post_id = get_the_ID();
if ($column == 'publication_date') {
$post_date = get_the_date('F Y', $post_id);
echo $post_date;
}
if ($column == 'revue_issue_number') {
$revue_issue_number = get_field('issue_number', $post_id);
if (!isset($revue_issue_number)) {
echo '×';
} else {
echo $revue_issue_number;
}
}
}
add_action('manage_revues_posts_custom_column', 'carhop_revues_handle_posts_custom_columns', 10, 2);