ACF 如何更新查询中的单个字段
ACF How to update a single field in a query
我需要根据以下代码仅在满足条件(购买值和使用值相等)时更新特定 post 的无线电字段。相反,这会更新所有 post 上的无线电选择。需要帮助解决这个问题。
如果我可以使用任何其他替代方法来满足此要求,也请提及。
<?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(); ?>
您没有在以下代码的 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 总是会被执行。
只需将 'if' 更改为:
if ($number_of_enquiries == $used) { expired(); rto_deactivation(); }
我需要根据以下代码仅在满足条件(购买值和使用值相等)时更新特定 post 的无线电字段。相反,这会更新所有 post 上的无线电选择。需要帮助解决这个问题。
如果我可以使用任何其他替代方法来满足此要求,也请提及。
<?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(); ?>
您没有在以下代码的 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 总是会被执行。
只需将 'if' 更改为:
if ($number_of_enquiries == $used) { expired(); rto_deactivation(); }