我需要更新一个特定的职位无线电字段,只有当条件满足(购买和使用的价值得到相同的),按照以下代码。相反,这将更新所有帖子上的无线电选择。需要帮助来解决这个问题。
如果有任何其他的替代方法,我可以使用以满足这一要求,请也提到这一点。
<?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(); ?>发布于 2017-09-18 01:09:31
在下面的代码中,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();只有在满足条件时才会调用...so expired();,但是rto_deactivation总是会被执行。
只需将“if”改为:
if ($number_of_enquiries == $used) { expired(); rto_deactivation(); }https://stackoverflow.com/questions/46270067
复制相似问题