我使用此代码显示使用重力表单在站点上进行的总捐赠。但如何限制只显示登录用户的捐赠?是的,用户已经进行了多次捐赠。
add_shortcode(\'donations\', \'total_donations\');
function total_donations($atts) {
$form_id = $atts[\'form\'];
// function to pull all the entries for one form
$donations = RGFormsModel::get_leads($form_id);
// start the total at zero
$total = 0;
// initialize a counter for the number of donations made
$i = 0;
// loop through all the returned results
foreach ($donations as $amount) {
// add each donation amount to the total
// change [49] here to the field ID which holds the donation amount
// the preg_replace will strip anything that is not a number or decimal
$numeric_amount = preg_replace(\'/[^0-9\\.]/Uis\', \'\',$amount[49]);
$total += $numeric_amount;
// increment the counter so we know how many donations there are as well
$i++;
}
// do some formatting and return the html output from the shortcode
$output = "We have raised $" . $total /* . " from $i donors."*/;
// just the string above will be returned. You can style it here or where you are using the shortcode
return $output;
}
add_filter(\'widget_text\', \'do_shortcode\');