【发布时间】:2018-06-01 11:12:55
【问题描述】:
我正在尝试使用affiliatewp 创建会员排行榜。我能够获得我想要的每一个值,但是,在我使用的函数中,我使用了一个 foreach 循环来调用每个附属公司并显示当月的“销售额”。
function affiliate_leaderboard_function() {
global $wpdb;
$getallreferrals = $wpdb->get_results( "SELECT * FROM `wp_affiliate_wp_referrals`");
$getallaffiliates = $wpdb->get_results( "SELECT * FROM `wp_affiliate_wp_affiliates`");
$current_month = get_the_date("m");
$current_year = get_the_date("Y");
$current_date = get_the_date("Y-m-d");
$lastday = date('t',strtotime($current_date));
foreach ($getallaffiliates as $theaffiliate) {
$user_id = get_userdata( $theaffiliate->user_id );
$userfirstname = $user_id->first_name;
$userlastname = $user_id->last_name;
$totalreferrals = $theaffiliate->referrals;
$affiliate_id = $theaffiliate->affiliate_id;
$getaffreferrals = $wpdb->get_results( "SELECT `date` FROM `wp_affiliate_wp_referrals` WHERE `affiliate_id` = $affiliate_id AND `date` >= '$current_year-$current_month-01:00:00:00' AND `date` < '$current_year-$current_month-$lastday:23:59:59' ORDER BY `wp_affiliate_wp_referrals`.`referral_id` ASC");//Get all referrals by affiliate id
$closerstring = $userfirstname." | This Month's Sales: ".count($getaffreferrals)."<br>";
if(!empty($getaffreferrals)){
echo $closerstring;
}
}
}
add_shortcode('affiliate_leaderboard' , 'affiliate_leaderboard_function');
所以当我放置短代码并使用“echo $closerstring”时,它会吐出所有正确的数据,用户的名字后跟他们当月的销售额。但是内容顶部的简码输出。
当我将它切换到“return $closerstring”时,它只返回一个附属而不是 foreach 循环中的所有附属。我不知道如何让它像 echo 函数那样显示所有值,但我需要它出现在正确的位置......
【问题讨论】:
标签: php wordpress foreach affiliate