From d7c81e6bbc23b1433997e5f929ea727b3e3b6a61 Mon Sep 17 00:00:00 2001 From: Joaquim d'Souza Date: Fri, 1 Dec 2023 19:38:21 +0100 Subject: [PATCH] fix: improve post organisation reliability --- web/app/themes/awasqa/src/queries.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/web/app/themes/awasqa/src/queries.php b/web/app/themes/awasqa/src/queries.php index d5c9d9b..2a7a246 100644 --- a/web/app/themes/awasqa/src/queries.php +++ b/web/app/themes/awasqa/src/queries.php @@ -109,7 +109,15 @@ function get_org_post_ids($org_id) if (!$org_ids) { $org_ids = [0]; } - $query['post__in'] = $org_ids; + // Add these in for better reliability, sometimes WPML fails to do this itself + $translated_post_ids = []; + foreach ($org_ids as $org_id) { + $en_id = apply_filters('wpml_object_id', $org_id, 'awasqa_organisation', true, 'en'); + $es_id = apply_filters('wpml_object_id', $org_id, 'awasqa_organisation', true, 'es'); + $translated_post_ids[] = $en_id; + $translated_post_ids[] = $es_id; + } + $query['post__in'] = array_merge($org_ids, $translated_post_ids); # Prevent sticky posts from always appearing $query['ignore_sticky_posts'] = 1; return $query;