FEATURE Introducing get_revue_terms utility

This commit is contained in:
Nonimart 2025-06-25 18:11:19 +02:00
parent 866f25d73f
commit d31693e9e3

View File

@ -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)
{