FEAT Introducing getRevueAuthors function

This commit is contained in:
Nonimart 2025-06-12 08:53:37 +02:00
parent 141a2aa985
commit ea89cd61cc

View File

@ -0,0 +1,49 @@
<?php
function getRevueAuthors($revueID)
{
$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' => '=',
),
),
));
$authors = array();
foreach ($revueRelatedArticles->posts as $article) {
$currentArticleAuthors = get_field('authors', $article->ID);
if (empty($currentArticleAuthors) || !is_array($currentArticleAuthors)) continue;
foreach ($currentArticleAuthors as $authorID) {
$authors[] = $authorID;
}
}
return array_unique($authors);
s;
}
function count_user_articles($userID, $postType)
{
$args = array(
'post_type' => $postType,
'meta_query' => array(
array(
'key' => 'authors',
'value' => '"' . $userID . '"',
'compare' => 'LIKE',
),
),
);
$query = new WP_Query($args);
return $query->found_posts;
}