当人们在页面中多次捐款时, 它只会显示他们最近的捐款, 而不是他们的总捐款(在捐款列表中)。例如, 如果我现在捐赠5美元, 以后再捐赠10美元, 它将仅显示10美元, 而不显示5美元。那是网站:gesher-jds.org/giving-tuesday
我如何解决它?
<
div class="donors_info">
<
div class="totalenteries">
<
/div>
<
?php
$valueid = 2727;
//Get donors based on forms IDs (can be single or multiple forms)
if(function_exists('give_get_payments')) {
$args = array(
'give_forms' =>
$valueid, 'number' =>
-1, );
$donations = give_get_payments( $args );
echo "<
table id='dtab'>
";
echo "<
thead>
";
echo "<
th align='center'>
" . 'Name' . "<
/th>
";
echo "<
th align='center'>
" . 'Amount' . "<
/th>
";
echo "<
/thead>
";
echo "<
tbody>
";
$donors = array();
foreach($donations as $donation) {
//Now get donor information from this donation ("customer" aka "donor")
$customer_id = give_get_payment_customer_id( $donation->
ID );
$customers= new Give_Customer( $customer_id );
$nameis = $customers->
name;
if (in_array($nameis, $donors)) {} else {
$amt = get_post_meta($donation->
ID, '_give_payment_total', true) + 0;
echo "<
tr class='select'>
";
echo "<
td align='left'>
" . $nameis . "<
/td>
";
echo "<
td align='center'>
" . $purchaseis = "$" . $amt . "<
/td>
";
echo "<
/tr>
";
$donors[] = $nameis;
}
}
echo "<
/tbody>
";
echo "<
/table>
";
}
?>
<
/div>
#1
$amt = get_post_meta($donation->
ID, '_give_payment_total', true)
” true” 仅返回指定元键的第一个值, ” false” 将为你提供元值数组。你可以使用foreach迭代返回的数组。
【捐赠列表-代码问题(代码有问题)】
get_post_meta()
编辑:
是的, 你需要将其更改为false, 然后获得一个值数组。现在, 你仅获得一个值。
然后迭代数组:
$amt = get_post_meta($donation->
ID, '_give_payment_total', false);
foreach ($amt as as $key =>
$value) {
echo "<
tr class='select'>
";
echo "<
td align='left'>
" . $nameis . "<
/td>
";
echo "<
td align='center'>
" . $purchaseis = "$" . $value . "<
/td>
";
echo "<
/tr>
";
}
代码未经检查, 但这是可行的方法。有关foreach的一些信息:
https://www.php.net/manual/de/control-structures.foreach.php
编辑2:如果要在一行中显示所有捐款:
<
div class="donors_info">
<
div class="totalenteries">
<
/div>
<
?php
$valueid = 2727;
//Get donors based on forms IDs (can be single or multiple forms)
if(function_exists('give_get_payments')) {
$args = array(
'give_forms' =>
$valueid, 'number' =>
-1, );
$donations = give_get_payments( $args );
echo "<
table id='dtab'>
";
echo "<
thead>
";
echo "<
th align='center'>
" . 'Name' . "<
/th>
";
echo "<
th align='center'>
" . 'Amount' . "<
/th>
";
echo "<
/thead>
";
echo "<
tbody>
";
$donors = array();
$dtmp=array();
//tmp array
foreach($donations as $donation) {
//Now get donor information from this donation ("customer" aka "donor")
$customer_id = give_get_payment_customer_id( $donation->
ID );
$customers= new Give_Customer( $customer_id );
$nameis = $customers->
name;
$amt = get_post_meta($donation->
ID, '_give_payment_total', false);
$donationAll = 0;
foreach ($amt as $key =>
$value) {
$donationAll = $donationAll + $value;
}
//Write a tmp array with name as key and donation as value
if(array_key_exists($nameis, $dtmp)) {
//name already exists ->
add donation value
$dtmp[$nameis] = $dtmp[$nameis] + $donationAll;
} else {
//name is not in the array ->
new array: key name ->
donation
$dtmp[$nameis] = $donationAll;
}$donors[] = $nameis;
}foreach ($dtmp as $key =>
$value) {
//iterate the tmp array
echo "<
tr class='select'>
";
echo "<
td align='left'>
" . $key . "<
/td>
";
echo "<
td align='center'>
" . $purchaseis = "$" . $value . "<
/td>
";
echo "<
/tr>
";
}echo "<
/tbody>
";
echo "<
/table>
";
}
?>
<
/div>
代码未选中。
问候汤姆
推荐阅读
- 使用Elementor的高级自定义字段
- WordPress中的CSS(自定义 vs 子主题)
- CSS-禁用菜单动画
- SQL query()方法是否以任何方式影响WordPress()
- 在线激活wordpress主题时,div不会浮动-在localhost上可以
- DIV在结帐页面上生成了2次(WOO COMMERCE)()
- Divi(桌面视图中的部分突然消失)
- Divi(限制点击次数按钮)
- 在centos 下 设计“安全”的delete命令替代rm。