• Resolved rynecallahan

    (@rynecallahan)


    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!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter rynecallahan

    (@rynecallahan)

    Here, I’m also trying this line of code. But it just isn’t populating in the field. I got this from another thread elsewhere.

    add_action('acf/save_post','calc_titles');
    $post_id = "teams";
    
    function calc_titles($post_id) {
    	$queried_object = get_queried_object();
        $value = get_field('16th_region_title_year_won', $queried_object);
    	$count = count($value);
    	$sixteen = "total_16th_region_titles";
    	update_field($sixteen,$value,$count,$post_id);
    }
    Thread Starter rynecallahan

    (@rynecallahan)

    Resolved!

    add_action('acf/save_post','calc_titles');
    $post_id = "teams";
    
    function calc_titles($post_id) {
    	
    	$value = count(get_field('16th_region_title_year_won'));
    	$sixteen = "total_16th_region_titles";
    	update_field($sixteen,$value,$post_id);
    }
    Thread Starter rynecallahan

    (@rynecallahan)

    Marked resolved.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Checkboxes Count = Number Field’ is closed to new replies.