2017-09-18 4 views
1

特定の投稿のラジオフィールドを更新する必要があるのは、条件が満たされたとき(購入した値と使用された値が等しい場合のみ)のコードです。代わりに、これはすべての投稿のラジオ選択を更新します。これを解決するために助けが必要です。ACF質問の単一フィールドを更新する方法

この要件を満たすために使用できる他の代替方法がある場合は、それも言及してください。

<td class="<?php if ($number_of_enquiries == $used) echo 'red'; ?>"> 
    <?php if ($number_of_enquiries == $used) expired(); rto_deactivation(); ?> 
</td> 

あなたはif条件が満たされたときに呼び出すラインの周りの任意の括弧を持っていない:条件は以下のコードであればあなたが内側にrto_deactivationへの呼び出しを持っていない

<?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

は、なぜあなたはpost_idのためupdate_field' 'に' false'をを渡しているの? – FluffyKitten

+0

現在の投稿を更新します。 Ref:https://www.advancedcustomfields.com/resources/update_field/ – JudeAinsly

答えて

0

if ($number_of_enquiries == $used) expired(); rto_deactivation(); 

...そうexpired();条件が満たされた場合にのみ呼び出さ取得されていますが、rto_deactivationは常に実行されようとしています。

ただ、これに '場合は、' 変更:

if ($number_of_enquiries == $used) { expired(); rto_deactivation(); } 
関連する問題