working on getPostMainThematique escapements

This commit is contained in:
Antoine M 2024-05-27 12:18:40 +02:00
parent 4823dd6378
commit ccccbf238e

View File

@ -74,10 +74,16 @@ function getMainThematique($thematique)
return get_term($thematique->parent, 'thematiques'); 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) 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 // TO GET ARCHIVE RELATED PAGES BY TEMPLATE
@ -137,9 +143,16 @@ function compareThematiquePriority($postA, $postB)
$thematiqueA = getPostMainThematique($postA); $thematiqueA = getPostMainThematique($postA);
$thematiqueB = getPostMainThematique($postB); $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); return strcmp($thematiqueA->name, $thematiqueB->name);
} }
if ($priorityA == $priorityB && $thematiqueA->name == $thematiqueB->name) {
return strcmp($postA->title, $postB->title);
}
if ($priorityA < $priorityB) { if ($priorityA < $priorityB) {
return 1; return 1;
} }