我需要根据以下代码在条件满足(购买和使用的值相等)时更新特定帖子的无线电字段。相反,这会更新所有帖子上的电台选择。需要帮助解决这个问题。
如果我可以使用任何其他替代方法来满足此要求,请同时提及。
<?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(); ?>
答案 0 :(得分:0)
您还没有在以下代码中的if条件中调用rto_deactivation:
<td class="<?php if ($number_of_enquiries == $used) echo 'red'; ?>">
<?php if ($number_of_enquiries == $used) expired(); rto_deactivation(); ?>
</td>
在满足if
条件时,您不会在线路周围拨打任何大括号:
if ($number_of_enquiries == $used) expired(); rto_deactivation();
...所以只有在满足条件时才调用expired();
,但总会执行rto_deactivation。
只需更改&#39; if&#39;对此:
if ($number_of_enquiries == $used) { expired(); rto_deactivation(); }