为了账号安全,请及时绑定邮箱和手机立即绑定

如何在自定义帖子类型 ACF WORDPRESS 的同一字段中计算()值

如何在自定义帖子类型 ACF WORDPRESS 的同一字段中计算()值

PHP
跃然一笑 2022-10-22 15:29:14
我的自定义帖子类型中有字段名称“金额”,我想要的只是每次我使用通过 ACF 创建的金额字段发布时都会计数()字段金额前任。loop  // The task is a post in custom post type different amount   // the first value post ex. 10, Second post 20, Third post will be 30  // I am trying this but not work  $varAmount = get_field('amount');  $varCount = count($varAmount); echo $varCount;  Output expected is: 60  // but showing 1010101;  // how to do that 60 instead of 101010?/loop$faq = new  WP_Query($args_faqs);if ( $faq->have_posts() ) {/* * Begin the loop tags post */    #echo count(get_field('loan_amount_applied'));     $total_amount = 0;      $amountapplied = get_field('loan_amount_applied');      $total_amount += $amountapplied;      $varCount = count($total_amount);      // array() = $amountapplied);     // if(is_array($amountappliedCOntainer)) {     // $total_amount = count($amountappliedCOntainer);while ( $faq->have_posts() ) {         $faq->the_post();
查看完整描述

1 回答

?
HUWWW

TA贡献1874条经验 获得超12个赞

由于您需要计算多个帖子的值,因此您需要在循环外初始化一个值为 0 的变量。然后您需要将金额(ACF FIELD)的值添加到该变量,然后回显它。


使用下面的代码。


<?php if ( have_posts() ) : 


$counter = 0;


/* Start the Loop */

while ( have_posts() ) :

the_post();

$varAmount = get_field('amount');

$counter += $varAmount;

echo $counter;

endwhile;


endif;

?>


查看完整回答
反对 回复 2022-10-22
  • 1 回答
  • 0 关注
  • 135 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号