Support

Account

Home Forums General Issues How to get total number of checkboxes checked

Solved

How to get total number of checkboxes checked

  • I can’t believe I haven’t been able to find this answer, and I feel like a novice for not being able to figure it out.

    How would I get the total number of checkboxes checked? I need to be able to assign a class to my wrappers that will vary based on that total number, which I can do easily if I have the total.

    Thanks in advance for any help!

  • Are we talking about a basic checkbox field?

    
    $value = get_field('checkbox_field_name');
    $count = count($value);
    
  • My bad. I forgot to mention (or realize) I was trying to get this to work on a custom taxonomy page, so I forgot to include get_queried_object();

    Resolved now, thanks to my brain fart. Thanks for jogging my mind, John Huebner!

    In case anyone else needs it, here’s my fixed code.

    $queried_object = get_queried_object();
    $seals = get_field('seals', $queried_object);
    $countSeals = count($seals);
Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘How to get total number of checkboxes checked’ is closed to new replies.