Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8393835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:54:24+00:00 2026-06-09T19:54:24+00:00

I have two functions one is hook and the other is filter. Hook function

  • 0

I have two functions one is hook and the other is filter.
Hook function displays all categories with input type(checkbox) thats simple.
But I have a problem with filter function when it is checked it’s updated and stored in DB but when I uncheck it I can’t update that field to be unchecked (to be updated in DB)

Here is the code of hook function:

function my_account_add_extra_field_kategorija() {
    global $current_user;
    
    $taxonomy     = 'category';
    $orderby      = 'name'; 
    $show_count   = 1;      // 1 for yes, 0 for no
    $pad_counts   = 1;      // 1 for yes, 0 for no
    $hierarchical = 1;      // 1 for yes, 0 for no
    $title        = '';
    $fcats        = '';
    $i            = 0;
    $args = array(
    'taxonomy'     => $taxonomy,
    'orderby'      => $orderby,
    'show_count'   => $show_count,
    'pad_counts'   => $pad_counts,
    'hierarchical' => $hierarchical,
    'title_li'     => $title,
    'hide_empty'    => 0
    );
    $cats  = get_categories( $args );
    print '<ul>';
    foreach($cats as $cat){   if($cat->parent == 0){ $fcats .= $cat->cat_ID.",";
    $cat_name = $cat->cat_name;
    $userID = $current_user->ID;
    $get_meta_value = get_the_author_meta( $cat_name, $userID );
    if($i%2){ $ex ="space"; }else{ $ex =""; }
    if($i == 10){ print '<div class="clearfix"></div>'; $ex =""; $i=0;}
    
    print '<li>';       
    if($get_meta_value == 1 ) {
        print '<input type="checkbox" name="sel_cat[]" value="'.$cat_name.'" checked="checked" ';
        print '/>'.$cat_name;
    } else {
        print '<input type="checkbox" name="sel_cat[]" value="'.$cat_name.'" ';
        print '/>'.$cat_name;
    }
    print '</li>';
    $i++; } }
    print '</ul>';
    
    print '<div class="clearfix"></div>';

}

and here is the filters function:

function my_account_update_extra_field_kategorija() {
global $current_user;
$user_id = $current_user->ID;
if(isset($_POST['sel_cat'])){
    foreach($_POST['sel_cat'] as $check) {
        update_user_meta($user_id, $check, '1');
    }
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T19:54:26+00:00Added an answer on June 9, 2026 at 7:54 pm

    Since checkbox values are only submitted when checked (ie there is no way of specifying an unchecked value), then you will have to use the data that you used to create the checkboxes. You can then tell which were unchecked by comparing them with the data submitted (checked).

    Since you are naming your checkboxes with [] (array) this is the best method.

    If however you used fixed names like name=”bob” or name=”bob[1]” then the easiest way to make all values submittable is to prepend a hidden input with the same name and the unchecked value. Ticking the checkbox will then over-write the hidden value.

    ie

    <input type="hidden" name="bob" value="0" />
    <input type="checkbox" name="bob" value="1" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two functions, one which parses all the arguments sent to the function
I have two functions, one function calling the other. Below is a simple analogy
I have two functions, one creates paragraphs dynamically and the other function selects (changes
I have a function which returns a one-sided intersection of values between two input
I have two image swap functions and one works in Firefox and the other
I'm trying to have two functions checking each form input, one for onchange() and
I have two functions, one that creates a table like so: function return_formatted_results(result_no,addy,title,own_comment) {
I have two functions and i want to make it like one. function 1
I need to have two functions which one is the alias of the other
I have two functions in my model. First one: public function updateOwn($game,$own,$user) { $data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.