diff --git a/includes/utilities.php b/includes/utilities.php index 4de17d9..4d35681 100644 --- a/includes/utilities.php +++ b/includes/utilities.php @@ -74,10 +74,16 @@ function getMainThematique($thematique) return get_term($thematique->parent, 'thematiques'); } } -// DOES THE SAME THING AS ABOVE BUT RENAMED +// Retriev the main thematique for a spefic postID function getPostMainThematique($post) { - return getMainThematique(get_the_terms($post, "thematiques")[0]); + $terms = get_the_terms($post, "thematiques"); + if (!$terms) return null; + + $mainThematique = getMainThematique(get_the_terms($post, "thematiques")[0]); + if (!$mainThematique) return null; + + return $mainThematique; } // TO GET ARCHIVE RELATED PAGES BY TEMPLATE @@ -137,9 +143,16 @@ function compareThematiquePriority($postA, $postB) $thematiqueA = getPostMainThematique($postA); $thematiqueB = getPostMainThematique($postB); - if ($priorityA == $priorityB) { + + 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) { return 1; }