我正在寻找一个简单的代码来列出所有具有旁观者角色的用户,如果他们在本周输入了一个条目,请输入“是”,如果没有,请输入“否”
列出所有用户和当前周条目
1 个回复
SO网友:Paul \'Sparrow Hawk\' Biron
如果您所说的“发表文章”是指“发表了至少1篇文章”,那么以下内容可以做到(附带以下限制条件):
$args = array (
\'role\' => \'spectator\',
) ;
$spectators = new WP_User_Query ($args) ;
$users_with_recent_posts = array () ;
foreach ($spectators->get_results () as $user) {
$args = array (
// if you are interested in posts with a different
// post_type, then just change the following to
// be the post_type you\'re interested in
\'post_type\' => \'post\',
\'date_query\' => array (
\'after\' => \'7 days ago\',
\'inclusive\' => true,
),
\'author\' => $user->ID,
\'posts_per_page\' => 1,
) ;
$posts = new WP_Query ($args) ;
$users_with_recent_posts[$user->data->user_nicename] = $posts->found_posts > 0 ? \'yes\' : \'no\' ;
}
Proviso: 以上仅显示用户为yes
如果他们有至少1个职位pust_status
当前为publish
, i、 例如,如果一个用户在过去7天内发布了一篇帖子,但该帖子的post_status
更改为其他内容publish
它们将显示为no
如果这是他们在过去7天内发布的唯一帖子。如果你所说的“做一个条目”是指其他东西,那么请解释一下你的意思。