首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >ACF如何更新查询中的单个字段

ACF如何更新查询中的单个字段
EN

Stack Overflow用户
提问于 2017-09-18 00:25:26
回答 1查看 93关注 0票数 1

我需要更新一个特定的职位无线电字段,只有当条件满足(购买和使用的价值得到相同的),按照以下代码。相反,这将更新所有帖子上的无线电选择。需要帮助来解决这个问题。

如果有任何其他的替代方法,我可以使用以满足这一要求,请也提到这一点。

代码语言:javascript
运行
复制
<?php

function expired() {
  echo "Expired";
}

function rto_deactivation() {
  $post_id = false;
  update_field('field_59ba2159ddd3b', 'Deactive', $post_id);
}

// Issue on function rto_deactivation(), when calls all RTOs get deactivated

$i=1;
$args = array(
  'numberposts' => -1,
  'post_type'   => 'rto_providers',
  'meta_key'    => 'package',
  'meta_value'  => 'Casual RTO'
);

$the_query = new WP_Query( $args );

?>
<?php if( $the_query->have_posts() ): ?>

  <div class="table-responsive">
  <table class="table">
    <thead>
      <tr>
        <th>#</th>
        <th>RTO Name</th>
        <th>Email Address</th>
        <th>Purchased</th>
        <th>Used</th>
        <th>Status</th>
      </tr>
    </thead>
    <tbody>

  <?php 
  while( $the_query->have_posts() ) : $the_query->the_post(); 
  $email_id = get_field( 'email_address', $post_id );
  $number_of_enquiries = get_field( 'number_of_enquiries', $post_id );
  $account_activation = get_field( 'account_activation', $post_id );
  ?>
    <tr>
      <td><?php echo $i++; ?></td>
      <td><?php the_title(); ?></td>
      <td><?php echo $email_id; ?></td>
      <td><?php echo $number_of_enquiries; ?></td>

      <?php
      $used = $wpdb->get_var(" SELECT COUNT(*) FROM table_name WHERE form_name = 'Course Enquiry' AND field_value = '$email_id' ");
      ?>

      <td><?php echo $used; ?></td>
      <td class="<?php if ($number_of_enquiries == $used) echo 'red'; ?>"><?php if ($number_of_enquiries == $used) expired(); rto_deactivation(); ?></td>
    </tr>
  <?php endwhile; ?>
  </tbody>
  </table>
  </div>
<?php endif; ?>

<?php wp_reset_query(); ?>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-09-18 01:09:31

在下面的代码中,if条件中没有调用rto_deactivation:

代码语言:javascript
运行
复制
<td class="<?php if ($number_of_enquiries == $used) echo 'red'; ?>">
   <?php if ($number_of_enquiries == $used) expired(); rto_deactivation(); ?>
</td>

在满足if条件时,在行周围没有任何大括号可调用:

代码语言:javascript
运行
复制
if ($number_of_enquiries == $used) expired(); rto_deactivation();

只有在满足条件时才会调用...so expired();,但是rto_deactivation总是会被执行。

只需将“if”改为:

代码语言:javascript
运行
复制
if ($number_of_enquiries == $used) { expired(); rto_deactivation(); }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46270067

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档