REFACTOR Reorganising columns settings in 2 separates files for each post type
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
431d67826f
commit
3cccbb76e8
|
|
@ -4,7 +4,8 @@ require_once(__DIR__ . '/includes/errorlog.php');
|
|||
require_once(__DIR__ . '/includes/init.php');
|
||||
require_once(__DIR__ . '/includes/post_types.php');
|
||||
require_once(__DIR__ . '/includes/logos.php');
|
||||
require_once(__DIR__ . '/includes/columns.php');
|
||||
require_once(__DIR__ . '/includes/article-columns.php');
|
||||
require_once(__DIR__ . '/includes/revues-columns.php');
|
||||
require_once(__DIR__ . '/includes/revue.php');
|
||||
require_once(__DIR__ . '/includes/auteurs.php');
|
||||
require_once(__DIR__ . '/includes/article.php');
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ function carhop_articles_add_acf_posts_columns($columns)
|
|||
unset($columns['date']);
|
||||
}
|
||||
$customColumns = array(
|
||||
'revue_issue_number' => 'Numéro',
|
||||
'revue' => 'Revue',
|
||||
);
|
||||
$new_admin_col_arrays = array_slice($columns, 0, 2, true) + $customColumns + array_slice($columns, 2, count($columns) - 2, true);
|
||||
|
|
@ -30,7 +31,18 @@ add_filter('manage_articles_posts_columns', 'carhop_articles_add_acf_posts_colum
|
|||
function carhop_articles_handle_posts_custom_columns($column)
|
||||
{
|
||||
$post_id = get_the_ID();
|
||||
$related_revue_ID = get_field('related_revue', $post_id);
|
||||
|
||||
if ($column == 'revue_issue_number') {
|
||||
// $revue_issue_number = get_field('issue_number', $related_revue_ID);
|
||||
$revue_issue_number = get_post_meta($post_id, 'revue_issue_number', true);
|
||||
|
||||
if (!isset($revue_issue_number)) {
|
||||
echo '×';
|
||||
} else {
|
||||
echo $revue_issue_number;
|
||||
}
|
||||
}
|
||||
if ($column == 'revue') {
|
||||
$revue_id = get_field('related_revue', $post_id);
|
||||
if (!isset($revue_id)) {
|
||||
|
|
@ -42,3 +54,29 @@ function carhop_articles_handle_posts_custom_columns($column)
|
|||
}
|
||||
}
|
||||
add_action('manage_articles_posts_custom_column', 'carhop_articles_handle_posts_custom_columns', 10, 2);
|
||||
|
||||
|
||||
// **** RENDRE LA COLONNE TRIABLE
|
||||
function carhop_articles_make_columns_sortable($columns)
|
||||
{
|
||||
$columns['revue_issue_number'] = 'revue_issue_number';
|
||||
return $columns;
|
||||
}
|
||||
add_filter('manage_edit-articles_sortable_columns', 'carhop_articles_make_columns_sortable');
|
||||
|
||||
|
||||
// **** LOGIQUE DE TRI PERSONNALISÉ
|
||||
function carhop_articles_custom_orderby($query)
|
||||
{
|
||||
if (!is_admin()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$orderby = $query->get('orderby');
|
||||
|
||||
if ('revue_issue_number' == $orderby) {
|
||||
$query->set('meta_key', 'revue_issue_number');
|
||||
$query->set('orderby', 'meta_value_num');
|
||||
}
|
||||
}
|
||||
add_action('pre_get_posts', 'carhop_articles_custom_orderby');
|
||||
73
includes/revues-columns.php
Normal file
73
includes/revues-columns.php
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
<?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);
|
||||
Loading…
Reference in New Issue
Block a user