diff --git a/includes/utilities.php b/includes/utilities.php index 4d35681..43777c6 100644 --- a/includes/utilities.php +++ b/includes/utilities.php @@ -127,9 +127,6 @@ function show_post_type_label_name($post_type) } - - - /* --------- SORT BY THEMATIQUE PRIORITY -----------------*/ @@ -137,21 +134,25 @@ SORT BY THEMATIQUE PRIORITY // Fonction de comparaison pour trier par 'thematique_priority' utilisé par la fonction supérieur function compareThematiquePriority($postA, $postB) { + $priorityA = $postA->thematique_priority ?? 0; $priorityB = $postB->thematique_priority ?? 0; $thematiqueA = getPostMainThematique($postA); $thematiqueB = getPostMainThematique($postB); + $DocumentA = get_field('brochure_pdf', $postA->ID); + $DocumentB = get_field('brochure_pdf', $postB->ID); + + $titleA = $DocumentA['title'] ?? null; + $titleB = $DocumentB['title'] ?? null; + - write_log('############## post A'); - // write_log($postA); - write_log("####" . $thematiqueA->name); if ($priorityA == $priorityB && $thematiqueA->name != $thematiqueB->name) { return strcmp($thematiqueA->name, $thematiqueB->name); } - if ($priorityA == $priorityB && $thematiqueA->name == $thematiqueB->name) { - return strcmp($postA->title, $postB->title); + if ($priorityA == $priorityB && $thematiqueA->name == $thematiqueB->name && $titleA && $titleB) { + return strcmp($titleA, $titleB); } if ($priorityA < $priorityB) { return 1; @@ -177,6 +178,7 @@ function sort_posts_per_thematiques_priority($postsQuery) } + /* ------------------------------------------- Build The page chaptering index ---------------------------------------------*/