Wordpress 列出今天生日的用户
Wordpress list users who has their birthday today
我的系统中有 800 多个用户个人资料,用户个人资料中有一个额外的字段可以输入他们的生日。 (使用 ACF 创建)
我需要显示今天生日的用户的名字。
我尝试了几次以下查询,但由于年份的原因,我无法将日期与今天的日期相匹配。
<?php
$today = date("M d y");
$blogusers = get_users(array(
'role' => 'subscriber',
'meta_key' => 'date_of_birth',
'orderby' => 'meta_value',
'order' => 'DESC',
));
foreach($blogusers as $user){
$name = $user->first_name;
$date = $user->date_of_birth;
$date = new DateTime($date);
?>
<div class="person">
<div class="col-sm-8"><?php echo $name; ?></div>
<div class="col-sm-4 text-right"><?php echo $date->format('M d y'); ?></div>
<div class="clear"></div>
</div>
<?php } ?>
<?php
$today = date("M d");
$blogusers = get_users(array(
'role' => 'subscriber',
'meta_key' => 'date_of_birth',
'orderby' => 'meta_value',
'order' => 'DESC',
));
foreach($blogusers as $user){
$name = $user->first_name;
$date = $user->date_of_birth;
$date = date("M d",strtotime($date));
if($today == $date){
?>
<div class="person">
<div class="col-sm-8"><?php echo $name; ?></div>
<div class="col-sm-4 text-right"><?php echo $date; ?></div>
<div class="clear"></div>
</div>
<?php
}
}
?>
我的系统中有 800 多个用户个人资料,用户个人资料中有一个额外的字段可以输入他们的生日。 (使用 ACF 创建) 我需要显示今天生日的用户的名字。
我尝试了几次以下查询,但由于年份的原因,我无法将日期与今天的日期相匹配。
<?php
$today = date("M d y");
$blogusers = get_users(array(
'role' => 'subscriber',
'meta_key' => 'date_of_birth',
'orderby' => 'meta_value',
'order' => 'DESC',
));
foreach($blogusers as $user){
$name = $user->first_name;
$date = $user->date_of_birth;
$date = new DateTime($date);
?>
<div class="person">
<div class="col-sm-8"><?php echo $name; ?></div>
<div class="col-sm-4 text-right"><?php echo $date->format('M d y'); ?></div>
<div class="clear"></div>
</div>
<?php } ?>
<?php
$today = date("M d");
$blogusers = get_users(array(
'role' => 'subscriber',
'meta_key' => 'date_of_birth',
'orderby' => 'meta_value',
'order' => 'DESC',
));
foreach($blogusers as $user){
$name = $user->first_name;
$date = $user->date_of_birth;
$date = date("M d",strtotime($date));
if($today == $date){
?>
<div class="person">
<div class="col-sm-8"><?php echo $name; ?></div>
<div class="col-sm-4 text-right"><?php echo $date; ?></div>
<div class="clear"></div>
</div>
<?php
}
}
?>