isset $_POST do nothing for update taxonomy

Question

Hello I created a taxonomy in the user part (‘user_activities’). I would just like to be able to save the changes on frontend with wp_set_object_terms() but if(!isset($_POST['user_activities'][$useractivitie->term_id])) dont work.

Here is my code:

HTML VIEW:

<div class="multiselect">

<div id="user_activities_form">
       <label for="user_activities-randonnee">
        <input type="checkbox" name="user_activities[randonnee]" id="user_activities-randonnee" value="10028">
        RANDONNEE          </label><br>
       <label for="user_activities-vtt">
        <input type="checkbox" name="user_activities[vtt]" id="user_activities-vtt" value="10029">
        VTT          </label><br>
          
</div>

UPDATE FUNCTION:

             $current_user   =   wp_get_current_user();
             $userID         =   $current_user->ID;
             $useractivities = get_terms($_POST['user_activities'], array( 'hide_empty' => false ) );

             
 foreach($useractivities as $useractivitie){
    $useractivitieID = $useractivitie->term_id;
    if ('POST' === $_SERVER['REQUEST_METHOD']) {
                if(!isset($_POST['user_activities'][$useractivitie->term_id]))
                wp_set_object_terms($userID,$useractivitieID,'user_activities',false); 
                else 
                wp_set_object_terms($userID,$useractivitieID,'user_activities',true); 

    }   
 }

Why the isset do nothing in the update function?
Thanks for your help !

0
Anarko 4 months 0 Answers 7 views 0

Leave an answer