updating post Sorting algorythm to handle poste title

This commit is contained in:
Antoine M 2024-05-27 15:19:34 +02:00
parent a8c091f272
commit c1f9be6366

View File

@ -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
---------------------------------------------*/