From d31693e9e3d020ccdbdc7ecf3b9572617160668b Mon Sep 17 00:00:00 2001 From: Nonimart Date: Wed, 25 Jun 2025 18:11:19 +0200 Subject: [PATCH] FEATURE Introducing get_revue_terms utility --- includes/utilities.php | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/includes/utilities.php b/includes/utilities.php index 47fd314..db3770d 100644 --- a/includes/utilities.php +++ b/includes/utilities.php @@ -2,8 +2,6 @@ function getRevueAuthors($revueID) { - - $revueRelatedArticles = new WP_Query(array( 'post_type' => 'articles', 'posts_per_page' => -1, @@ -30,6 +28,40 @@ function getRevueAuthors($revueID) return array_unique($authors); } +function get_revue_terms($revueID, $taxonomy) +{ + $revueRelatedArticles = new WP_Query(array( + 'post_type' => 'articles', + 'posts_per_page' => -1, + 'post_status' => 'publish', + 'meta_query' => array( + array( + 'key' => 'related_revue', + 'value' => $revueID, + 'compare' => '=', + ), + ), + )); + $terms = array(); + + foreach ($revueRelatedArticles->posts as $article) { + $currentArticleTerms = get_the_terms($article->ID, $taxonomy); + + if (empty($currentArticleTerms) || !is_array($currentArticleTerms)) continue; + + foreach ($currentArticleTerms as $term) { + $terms[] = $term->term_id; + } + } + + foreach (array_unique($terms) as $term) { + $termObject = get_term($term, $taxonomy); + $uniquesTermsArray[] = $termObject; + } + + return $uniquesTermsArray; +} + function count_user_articles($userID, $postType) {