Checkboxes Count = Number Field

[ad_1]

add_action('acf/save_post', 'count_titles');

function count_titles($post_id)
{
	$post_id = "teams";

	// ACF teams field values.
	$sixteenRegion = get_field('16th_region_title_year_won', 'teams');

	// Calculate total pets.
	$calcSixteen = count($sixteenRegion);

	// Update ACF field for total_pets.
	update_field('total_16th_region_titles', $calcSixteen, $post_id);
}

add_filter('acf/format_value/type=number', 'format_numbers');

function format_numbers($value, $post_id, $field)
{
	$value = number_format($value);
	
	return $value;
}

I know this code is probably very wrong. I’ve tried piecing it together from other researching common threads but I can’t seem to get it to work the way I want it.

I am trying to autopopulate the number field based on how many checkboxes are checked in another field. So for example, if the checkbox field has 5 of the 16 checkboxes checked. Then “5” should be populated in the number field above. I keep getting an error and it’s probably from just a dumb syntax error or just plain wrong code. IAny help would be great!

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer